├── .github
├── banner.png
└── workflows
│ └── tests.yml
├── .gitignore
├── LICENSE
├── Plugin.php
├── README.md
├── assets
├── dist
│ └── js
│ │ ├── blocks.js
│ │ └── blocks.js.LICENSE.txt
└── src
│ └── js
│ ├── blocks.js
│ └── utilities
│ └── Actions.js
├── blocks
├── button.block
├── button_group.block
├── cards.block
├── code.block
├── columns_two.block
├── divider.block
├── image.block
├── plaintext.block
├── richtext.block
├── title.block
├── video.block
├── vimeo.block
└── youtube.block
├── classes
├── Block.php
├── BlockBuilder.php
├── BlockCode.php
├── BlockManager.php
├── BlockParser.php
├── BlockProcessor.php
└── BlocksDatasource.php
├── codecov.yml
├── composer.json
├── formwidgets
├── Block.php
├── Blocks.php
└── blocks
│ ├── assets
│ ├── css
│ │ └── blocks.css
│ ├── js
│ │ └── blocks.js
│ └── less
│ │ └── blocks.less
│ └── partials
│ ├── _block.php
│ ├── _block_add_item.php
│ └── _block_item.php
├── lang
├── en
│ └── lang.php
└── fr
│ └── lang.php
├── meta
└── actions.yaml
├── phpunit.xml
├── tests
├── PluginTest.php
├── classes
│ └── BlockManagerTest.php
├── fixtures
│ ├── blocks
│ │ ├── container.block
│ │ ├── richtext.block
│ │ └── title.block
│ ├── models
│ │ └── Page.php
│ └── themes
│ │ └── blocktest
│ │ └── blocks
│ │ └── title.block
└── formwidgets
│ └── BlocksTest.php
├── updates
└── version.yaml
└── winter.mix.js
/.github/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wintercms/wn-blocks-plugin/a3817d5f8027982690dfca0cc690c37b07653afb/.github/banner.png
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 |
9 | jobs:
10 | phpUnitTests:
11 | name: ${{ matrix.operatingSystem }} / PHP ${{ matrix.phpVersion }}
12 | runs-on: ${{ matrix.operatingSystem }}
13 | strategy:
14 | max-parallel: 4
15 | matrix:
16 | operatingSystem: [ubuntu-latest, windows-latest]
17 | phpVersion: ['8.1', '8.2', '8.3', '8.4']
18 | steps:
19 | - name: Setup Winter
20 | uses: wintercms/setup-winter-action@v1
21 | with:
22 | php-version: ${{ matrix.phpVersion }}
23 | plugin-author: winter
24 | plugin-name: blocks
25 |
26 | - name: Run tests
27 | if: matrix.phpVersion != '8.1' || matrix.operatingSystem != 'ubuntu-latest'
28 | run: php artisan winter:test -p Winter.Blocks -- --testdox
29 |
30 | - name: Run tests (and generate coverage report)
31 | if: matrix.phpVersion == '8.1' && matrix.operatingSystem == 'ubuntu-latest'
32 | env:
33 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
34 | run: |
35 | XDEBUG_MODE=coverage php artisan winter:test -p Winter.Blocks -- --testdox --coverage-clover coverage.xml
36 | bash <(curl -s https://codecov.io/bash)
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .phpunit.result.cache
2 | mix.webpack.js
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Winter CMS
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Plugin.php:
--------------------------------------------------------------------------------
1 | 'winter.blocks::lang.plugin.name',
31 | 'description' => 'winter.blocks::lang.plugin.description',
32 | 'author' => 'Winter CMS',
33 | 'icon' => 'icon-cubes',
34 | ];
35 | }
36 |
37 | /**
38 | * Registers the custom Blocks provided by this plugin
39 | */
40 | public function registerBlocks(): array
41 | {
42 | return [
43 | 'button' => '$/winter/blocks/blocks/button.block',
44 | 'button_group' => '$/winter/blocks/blocks/button_group.block',
45 | 'cards' => '$/winter/blocks/blocks/cards.block',
46 | 'code' => '$/winter/blocks/blocks/code.block',
47 | 'columns_two' => '$/winter/blocks/blocks/columns_two.block',
48 | 'divider' => '$/winter/blocks/blocks/divider.block',
49 | 'image' => '$/winter/blocks/blocks/image.block',
50 | 'plaintext' => '$/winter/blocks/blocks/plaintext.block',
51 | 'richtext' => '$/winter/blocks/blocks/richtext.block',
52 | 'title' => '$/winter/blocks/blocks/title.block',
53 | 'video' => '$/winter/blocks/blocks/video.block',
54 | 'vimeo' => '$/winter/blocks/blocks/vimeo.block',
55 | 'youtube' => '$/winter/blocks/blocks/youtube.block',
56 | ];
57 | }
58 |
59 | /**
60 | * Registers the custom FormWidgets provided by this plugin
61 | */
62 | public function registerFormWidgets(): array
63 | {
64 | return [
65 | \Winter\Blocks\FormWidgets\Blocks::class => 'blocks'
66 | ];
67 | }
68 |
69 | /**
70 | * Registers the custom twig markups provided by this plugin
71 | */
72 | public function registerMarkupTags()
73 | {
74 | return [
75 | 'functions' => [
76 | 'renderBlock' => [
77 | function (array $context, string|array $block, array $data = []) {
78 | return BlockModel::render(
79 | $block,
80 | $data,
81 | $context['this']['controller'] ?? null
82 | );
83 | },
84 | 'options' => ['needs_context' => true]
85 | ],
86 | 'renderBlocks' => [
87 | function (array $context, array $blocks) {
88 | return BlockModel::renderAll(
89 | $blocks,
90 | $context['this']['controller'] ?? null
91 | );
92 | },
93 | 'options' => ['needs_context' => true]
94 | ],
95 | ],
96 | ];
97 | }
98 |
99 | /**
100 | * Boot method, called right before the request route.
101 | */
102 | public function boot(): void
103 | {
104 | $this->extendThemeDatasource();
105 | $this->extendControlLibraryBlocks();
106 | }
107 |
108 | /**
109 | * Extend the theme's datasource to include the BlocksDatasource for loading blocks from
110 | */
111 | protected function extendThemeDatasource(): void
112 | {
113 | // Register the block manager instance
114 | BlockManager::instance();
115 | Event::listen('cms.theme.registerHalcyonDatasource', function (Theme $theme, $resolver) {
116 | $source = $theme->getDatasource();
117 | if ($source instanceof AutoDatasource) {
118 | /* @var AutoDatasource $source */
119 | $source->appendDatasource('blocks', new BlocksDatasource());
120 | return;
121 | } else {
122 | $resolver->addDatasource($theme->getDirName(), new AutoDatasource([
123 | 'theme' => $source,
124 | 'blocks' => new BlocksDatasource(),
125 | ], 'blocks-autodatasource'));
126 | }
127 | });
128 | }
129 |
130 | /**
131 | * Extend the ControlLibrary provided by Winter.Builder to register blocks as Form Controls
132 | */
133 | protected function extendControlLibraryBlocks(): void
134 | {
135 | // Register blocks as custom controls
136 | Event::listen('pages.builder.registerControls', function (\Winter\Builder\Classes\ControlLibrary $controlLibrary) {
137 | foreach (BlockManager::instance()->getConfigs('forms') as $key => $config) {
138 | // Map custom fields into standard properties, while ignoring irrelevant properties
139 | $properties = $controlLibrary->getStandardProperties([
140 | 'label', 'required', 'comment', 'placeholder', 'default', 'defaultFrom', 'stretch'
141 | ], array_combine(
142 | array_map(
143 | fn($field) => sprintf('data[%s]', $field),
144 | array_keys($config['fields'] ?? [])
145 | ),
146 | array_values(
147 | array_map(
148 | fn ($field) => array_merge($field, [
149 | 'title' => $field['label'] ?? '',
150 | 'tab' => 'Field Options'
151 | ]),
152 | $config['fields'] ?? []
153 | )
154 | )
155 | ));
156 |
157 | // Sort custom fields to the top
158 | uksort($properties, fn ($a, $b) => str_contains($key, 'data[') ? 1 : $a <=> $b);
159 |
160 | $controlLibrary->registerControl(
161 | Block::TYPE_PREFIX . $key,
162 | $config['name'],
163 | $config['description'],
164 | Block::GROUP_BLOCKS,
165 | $config['icon'],
166 | $properties,
167 | null
168 | );
169 | }
170 | }, PHP_INT_MIN);
171 |
172 | // Register a Winter\Blocks\FormWidgets\Block FormWidget under each block's key
173 | WidgetManager::instance()->registerFormWidgets(function ($manager) {
174 | foreach (BlockManager::instance()->getConfigs() as $key => $config) {
175 | $manager->registerFormWidget(Block::class, Block::TYPE_PREFIX . $key);
176 | }
177 | });
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Blocks Plugin
2 |
3 | 
4 |
5 | [](https://github.com/wintercms/wn-blocks-plugin/blob/main/LICENSE)
6 |
7 | Provides a "block based" content management experience in Winter CMS
8 |
9 | >**NOTE:** This plugin is still in development and is likely to undergo changes. Do not use in production environments without using a version constraint in your composer.json file and carefully monitoring for breaking changes.
10 |
11 | ## Installation
12 |
13 | This plugin is available for installation via [Composer](http://getcomposer.org/).
14 |
15 | ```bash
16 | composer require winter/wn-blocks-plugin
17 | ```
18 |
19 | After installing the plugin you will need to run the migrations and (if you are using a [public folder](https://wintercms.com/docs/develop/docs/setup/configuration#using-a-public-folder)) [republish your public directory](https://wintercms.com/docs/develop/docs/console/setup-maintenance#mirror-public-files).
20 |
21 | ```bash
22 | php artisan migrate
23 | ```
24 |
25 | >**NOTE:** In order to have the `actions` support function correctly, you need to load `/plugins/winter/blocks/assets/dist/js/blocks.js` after the Snowboard framework has been loaded.
26 |
27 | ## Core Concepts
28 |
29 | ### Blocks
30 |
31 | This plugin manages the concept of "blocks" in Winter CMS. Blocks are self contained pieces of structured content that can be managed and rendered in a variety of ways.
32 |
33 | Blocks can be provided by both plugins and themes and can be overridden by themes.
34 |
35 | ### Actions
36 |
37 | This plugin also introduces the concepts of "actions"; a way to define and execute client side actions that can be triggered by various events. Currently, actions are only defined in the `$/winter/blocks/meta/actions.yaml` file and must exist as a function on the `window.actions` object in the frontend keyed by the action's identifier that receives the `data` object as the first argument and (optionally) the `event` object that triggered the action as the second argument.
38 |
39 | >**NOTE:** This is very much a WIP API and is subject to change. Feedback very much welcome here for ideas around how to register, manage, extend, and provide actions to the frontend.
40 |
41 | ### Tags
42 |
43 | Blocks may have one or more tags, which is a way of defining and grouping blocks. For example, you may have a Gallery block which allows only "image" tagged blocks to be used, or a container block which allows all "content" tagged blocks but does not allow another "container" tagged block within.
44 |
45 | Tags are defined in the blocks, and can be used to filter the available blocks in the Blocks form widget.
46 |
47 |
48 | ## Registering Blocks
49 |
50 | Themes can have their blocks automatically registered by placing `.block` files in the `/blocks` folder and subfolders.
51 |
52 | Plugins can register blocks by providing a `registerBlocks()` method in their Plugin.php file. The method should return an array of block definitions in the following format:
53 |
54 | ```php
55 | public function registerBlocks(): array
56 | {
57 | return [
58 | 'example' => '$/myauthor/myplugin/blocks/example.block',
59 | ];
60 | }
61 | ```
62 |
63 |
68 |
69 |
70 | ## Block Definition
71 |
72 | Blocks are defined as `.block` files that consist of 2 to 3 parts:
73 |
74 | - A YAML configuration section that defines the block's name, description, and other metadata as well as the block's properties and the form used to edit those properties.
75 | - A PHP code section that allows for basic code to be executed when the block is rendered, similar to a partial.
76 | - A Twig template section that defines the HTML markup template of the block.
77 |
78 | When there are two parts, they are the Settings (YAML) & Markup (Twig) sections.
79 |
80 | The following property values (name, description, etc) can be defined in the Settings (YAML) section of the `.block` files:
81 |
82 | ```yaml
83 | name: Example
84 | description: Example Block Description
85 | icon: icon-name
86 | tags: [] # Defines the tags that this block is associated with
87 | permissions: [] # List of permissions required to interact with the block
88 | fields: # The form fields used to populate the block's content
89 | config: # The block configuration options
90 | ```
91 |
92 | Blocks can use components in them, although they may face lifecycle limitations with complex AJAX handlers similar to component support in partials.
93 |
94 | ### Fields and Configuration
95 |
96 | Blocks may define both `fields` as well as a `config` property in the Settings. Both of these parameters accept a [form schema](https://wintercms.com/docs/backend/forms#form-fields), but serve different purposes. In general, `fields` should contain the fields that actually fill in the content of the block, whereas the `config` should contain the fields that define the appearance or structure of the block itself. Fields are displayed within the block in the `blocks` form widget and configuration is displayed in an Inspector which can be shown by clicking on the "cogwheel" icon of a block in the `blocks` form widget.
97 |
98 | For example, let's say you have a **Title** block which can display a heading tag in your content. You may optionally want to align it to left, center or right, and define which heading tag to use. The best practice would be to have a `content` field in the `fields` definition, because it's the actual content being displayed. The `alignment` and `tag` would become part of the `config` configuration.
99 |
100 | **Example:**
101 |
102 | ```
103 | name: Title
104 | description: Adds a title
105 | icon: icon-heading
106 | tags: ["content"]
107 | fields:
108 | content:
109 | label: false
110 | span: full
111 | type: text
112 | config:
113 | size:
114 | label: Size
115 | span: auto
116 | type: dropdown
117 | default: h2
118 | options:
119 | h1: H1
120 | h2: H2
121 | h3: H3
122 | h4: H4
123 | h5: H5
124 | alignment_x:
125 | label: Alignment
126 | span: auto
127 | type: dropdown
128 | default: center
129 | options:
130 | left: Left
131 | center: Centre
132 | right: Right
133 | ==
134 | {% if config.alignment_x == 'left' %}
135 | {% set alignment = 'text-left' %}
136 | {% elseif config.alignment_x == 'center' or not config.alignment_x %}
137 | {% set alignment = 'text-center' %}
138 | {% elseif config.alignment_x == 'right' %}
139 | {% set alignment = 'text-right' %}
140 | {% endif %}
141 |
142 | <{{ config.size }} class="{{ alignment }}">
143 | {{ content }}
144 | {{ config.size }}>
145 | ```
146 |
147 | ## Using the `blocks` FormWidget
148 |
149 | In order to provide an interface for managing block-based content, this plugin provides the `blocks` FormWidget. This widget can be used in the backend as a form field to manage blocks.
150 |
151 | The `blocks` FormWidget supports the following additional properties:
152 |
153 | - `allow`: An array of block types that are allowed to be added to the widget. If specified, only those block types listed will be available to add to the current instance of the field. You can define either a straight array of individual blocks to allow, or define an object with `tags` and/or `blocks` to allow whole tags or individual blocks.
154 | - `ignore`: A list of block types that are not allowed to be added to the widget. If not specified, all block types will be available to add to the current instance of the field. You can define either a straight array of individual blocks to ignore, or define an object with `tags` and/or `blocks` to ignore whole tags or individual blocks.
155 | - `tags`: A list of block tags that are allowed to be added to the widget. If specified, only block types that have at least one of the listed tags will be available to add to the current instance of the field.
156 |
157 | Those properties allow you to limit the block types that can be added to a specific instance of the widget, which can be very helpful when building "container" type blocks that need to avoid including themselves or only support a specific set of blocks as "children".
158 |
159 | ### Examples
160 |
161 | The `button_group` block type only allows a `button` block to be added to it:
162 |
163 | ```yaml
164 | buttons:
165 | label: Buttons
166 | span: full
167 | type: blocks
168 | allow:
169 | - button
170 | ```
171 |
172 | The `container` block type allows any block called `title`, or has a tag of `content`, to be added to it:
173 |
174 | ```yaml
175 | container:
176 | label: Container
177 | span: full
178 | type: blocks
179 | allow:
180 | blocks:
181 | - title
182 | tags:
183 | - content
184 | ```
185 |
186 | The `columns_two` block type allows every block except for itself to be added to it:
187 |
188 | ```yaml
189 | left:
190 | label: Left Column
191 | span: left
192 | type: blocks
193 | ignore:
194 | - columns_two
195 | right:
196 | label: Right Column
197 | span: right
198 | type: blocks
199 | ignore:
200 | - columns_two
201 | ```
202 |
203 | ### Integration with the Winter.Pages plugin:
204 |
205 | Include the following line in your layout file to include the blocks FormWidget on a Winter.Pages page:
206 |
207 | ```twig
208 | {variable type="blocks" name="blocks" tags="pages" tab="winter.pages::lang.editor.content"}{/variable}
209 | ```
210 |
211 |
212 | ## Rendering Blocks
213 |
214 | ### Using Twig
215 |
216 | Twig functions are provided by this plugin for rendering blocks.
217 | You can then use the following Twig snippet to render the blocks data in your layout:
218 |
219 | ```twig
220 | {{ renderBlocks(blocks) }}
221 | ```
222 |
223 | You can use it anywhere an expression is accepted:
224 |
225 | ```twig
226 | {{ ('
Some text
' ~ renderBlocks(blocks) ~ '
Some more text
') | raw }}
227 |
228 | {% set myContent = renderBlocks(blocks) %}
229 | ```
230 |
231 | If you need to render a single block, you can use the `renderBlock` function:
232 |
233 | ```twig
234 | {{ renderBlock({
235 | '_group':'title',
236 | 'content':'Lorem ipsum dolor sit amet.',
237 | 'alignment_x':'left',
238 | 'size':'h1',
239 | }) }}
240 |
241 | {{ renderBlock('title', {
242 | 'content':'Lorem ipsum dolor sit amet.',
243 | 'alignment_x':'left',
244 | 'size':'h1',
245 | }) }}
246 | ```
247 |
248 | ### Using a partial
249 |
250 | If you need to customize the rendering of blocks according to their group, you can use a special `blocks.htm` partial in your theme:
251 |
252 | ```twig
253 | {% for blockIndex, block in blocks %}
254 | {# Adding blocks to the following array allows them to implement their own containers #}
255 | {% if block._group in ["hero", "section"] %}
256 | {{ renderBlock(block) }}
257 | {% else %}
258 |
259 |
260 | {{ renderBlock(block) }}
261 |
262 |
263 | {% endif %}
264 | {% endfor %}
265 | ```
266 |
267 | You can then use the following Twig snippet to render the block data in your layout:
268 |
269 | ```twig
270 | {% partial 'blocks' blocks=blocks %}
271 | ```
272 |
273 | ### Using PHP
274 |
275 | ```php
276 | use Winter\Blocks\Classes\Block;
277 |
278 | // Render a single block from stored data
279 | Block::render($model->blocks[0]);
280 |
281 | // Render an array of blocks from stored data
282 | Block::renderAll($model->blocks);
283 |
284 | // Render a single block manually
285 | Block::render('title', [
286 | 'content' => 'Lorem ipsum dolor sit amet.',
287 | 'alignment_x' => 'left',
288 | 'size' => 'h1',
289 | ]);
290 |
291 | // Render a single block manually using only array data
292 | Block::render([
293 | '_group' => 'title',
294 | 'content' => 'Lorem ipsum dolor sit amet.',
295 | 'alignment_x' => 'left',
296 | 'size' => 'h1',
297 | ]);
298 | ```
299 |
300 |
301 | ## Integrating with TailwindCSS / CSS Purging
302 |
303 | If your theme uses CSS class purging (i.e. Tailwind), it can be useful to add the following paths to your build configuration to include the styles for any blocks defined by the theme or plugins.
304 |
305 | ```js
306 | // tailwind.config.js
307 | module.exports = {
308 | content: [
309 | // Winter.Pages static page content
310 | './content/**/*.htm',
311 | './layouts/**/*.htm',
312 | './pages/**/*.htm',
313 | './partials/**/*.htm',
314 | './blocks/**/*.block',
315 |
316 | // Blocks provided by plugins
317 | '../../plugins/*/*/blocks/*.block',
318 | ],
319 | };
320 | ```
321 |
322 |
323 | ## Feedback
324 |
325 | > The Winter.Blocks is perfect for my block-based themes. I've been looking for something like this for a long time
326 |
--------------------------------------------------------------------------------
/assets/dist/js/blocks.js:
--------------------------------------------------------------------------------
1 | /*! For license information please see blocks.js.LICENSE.txt */
2 | (()=>{"use strict";var t,r={331:()=>{function t(r){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(r)}function r(){r=function(){return e};var e={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},c=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",f=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=r&&r.prototype instanceof y?r:y,a=Object.create(o.prototype),c=new _(n||[]);return i(a,"_invoke",{value:x(t,e,c)}),a}function p(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}e.wrap=s;var h={};function y(){}function v(){}function d(){}var w={};l(w,c,(function(){return this}));var b=Object.getPrototypeOf,g=b&&b(b(S([])));g&&g!==n&&o.call(g,c)&&(w=g);var m=d.prototype=y.prototype=Object.create(w);function O(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function j(r,e){function n(i,a,c,u){var f=p(r[i],r,a);if("throw"!==f.type){var l=f.arg,s=l.value;return s&&"object"==t(s)&&o.call(s,"__await")?e.resolve(s.__await).then((function(t){n("next",t,c,u)}),(function(t){n("throw",t,c,u)})):e.resolve(s).then((function(t){l.value=t,c(l)}),(function(t){return n("throw",t,c,u)}))}u(f.arg)}var a;i(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return a=a?a.then(o,o):o()}})}function x(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return k()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=E(a,e);if(c){if(c===h)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var u=p(t,r,e);if("normal"===u.type){if(n=e.done?"completed":"suspendedYield",u.arg===h)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n="completed",e.method="throw",e.arg=u.arg)}}}function E(t,r){var e=r.method,n=t.iterator[e];if(void 0===n)return r.delegate=null,"throw"===e&&t.iterator.return&&(r.method="return",r.arg=void 0,E(t,r),"throw"===r.method)||"return"!==e&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+e+"' method")),h;var o=p(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,h;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,h):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function L(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function S(t){if(t){var r=t[c];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,n=function r(){for(;++e=0;--n){var i=this.tryEntries[n],a=i.completion;if("root"===i.tryLoc)return e("end");if(i.tryLoc<=this.prev){var c=o.call(i,"catchLoc"),u=o.call(i,"finallyLoc");if(c&&u){if(this.prev=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),L(e),h}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;L(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:S(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),h}},e}function e(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function n(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function o(t){for(var r=1;r{}},e={};function n(t){var o=e[t];if(void 0!==o)return o.exports;var i=e[t]={exports:{}};return r[t](i,i.exports,n),i.exports}n.m=r,t=[],n.O=(r,e,o,i)=>{if(!e){var a=1/0;for(l=0;l=i)&&Object.keys(n.O).every((t=>n.O[t](e[u])))?e.splice(u--,1):(c=!1,i0&&t[l-1][2]>i;l--)t[l]=t[l-1];t[l]=[e,o,i]},n.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),(()=>{var t={983:0,488:0};n.O.j=r=>0===t[r];var r=(r,e)=>{var o,i,[a,c,u]=e,f=0;if(a.some((r=>0!==t[r]))){for(o in c)n.o(c,o)&&(n.m[o]=c[o]);if(u)var l=u(n)}for(r&&r(e);fn(331)));var o=n.O(void 0,[488],(()=>n(60)));o=n.O(o)})();
--------------------------------------------------------------------------------
/assets/dist/js/blocks.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2 |
--------------------------------------------------------------------------------
/assets/src/js/blocks.js:
--------------------------------------------------------------------------------
1 | import Actions from './utilities/Actions';
2 |
3 | if (window.Snowboard === undefined) {
4 | throw new Error('Snowboard must be loaded in order to register the Blocks functionality.');
5 | }
6 |
7 | ((Snowboard) => {
8 | Snowboard.addPlugin('actions', Actions);
9 | })(window.Snowboard);
10 |
--------------------------------------------------------------------------------
/assets/src/js/utilities/Actions.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Action Processor
3 | *
4 | * You can process actions manually by calling the following:
5 | *
6 | * ```js
7 | * Snowboard.addPlugin('actions', Actions);
8 | * Snowboard.actions().doActions(actions, event);
9 | * ```
10 | *
11 | * @copyright 2023 Winter.
12 | * @author Luke Towers
13 | */
14 | export default class Actions extends window.Snowboard.Singleton {
15 | /**
16 | * @TODO: This is terrible, find a better way to manage the available actions
17 | */
18 | construct() {
19 | window.actions = window.actions || {};
20 | window.actions = {
21 | ...(window.actions || {}),
22 |
23 | open_url: (data, event) => {
24 | if (typeof data.target === "undefined") {
25 | data.target = "_self";
26 | }
27 |
28 | window.open(data.href, data.target);
29 | }
30 | };
31 | }
32 | /**
33 | * Run the provided actions.
34 | *
35 | * @param {array} actions
36 | * @param {Object} event
37 | */
38 | async doActions(actions, event) {
39 | if (event) {
40 | event.stopPropagation();
41 | }
42 |
43 | if (!Array.isArray(actions)) {
44 | console.error(`Actions is not an array`);
45 | return;
46 | }
47 |
48 | actions.forEach((action) => {
49 | // @TODO: Terrible, find a better way to handle dynamically registering available actions
50 | if (typeof window.actions[action.action] !== 'function') {
51 | console.error(`Action ${action.action} does not exist on the window object`);
52 | return;
53 | }
54 |
55 | window.actions[action.action](action.data, event);
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/blocks/button.block:
--------------------------------------------------------------------------------
1 | name: winter.blocks::lang.blocks.button.name
2 | description: winter.blocks::lang.blocks.button.description
3 | icon: icon-caret-square-o-right
4 | tags: ["pages"]
5 | fields:
6 | config:
7 | type: nestedform
8 | usePanelStyles: false
9 | form:
10 | fields:
11 | label:
12 | label: winter.blocks::lang.fields.label
13 | span: full
14 | type: text
15 | tabs:
16 | icons:
17 | winter.blocks::lang.fields.actions: 'icon-arrow-pointer'
18 | winter.blocks::lang.tabs.display: 'icon-brush'
19 |
20 | fields:
21 | actions:
22 | type: repeater
23 | tab: winter.blocks::lang.fields.actions
24 | prompt: winter.blocks::lang.fields.actions_prompt
25 | groups: $/winter/blocks/meta/actions.yaml
26 | color:
27 | label: winter.blocks::lang.fields.color
28 | tab: winter.blocks::lang.tabs.display
29 | span: auto
30 | type: colorpicker
31 | icon:
32 | label: winter.blocks::lang.fields.icon
33 | tab: winter.blocks::lang.tabs.display
34 | span: auto
35 | type: iconpicker
36 | ==
37 | controller->addJs(Url::asset('/plugins/winter/blocks/assets/dist/js/blocks.js'), 'Winter.Blocks');
43 |
44 | $data = $this['data']['config'];
45 |
46 | // Ensure actions are 0 indexed
47 | $data['actions'] = array_values($data['actions'] ?? []);
48 |
49 | if (!empty($data['actions'])) {
50 | foreach ($data['actions'] as &$config) {
51 | $action = $config['_group'] ?? '';
52 | unset($config['_group']);
53 |
54 | switch ($action) {
55 | case 'open_media':
56 | $config['href'] = MediaLibrary::url($config['media_file']);
57 | $action = 'open_url';
58 | break;
59 | }
60 |
61 | $config = [
62 | 'data' => $config,
63 | 'action' => $action,
64 | ];
65 | }
66 | }
67 |
68 | $this['data'] = array_merge($this['data'], [
69 | 'config' => $data
70 | ]);
71 | }
72 | ?>
73 | ==
74 |
89 |
--------------------------------------------------------------------------------
/blocks/button_group.block:
--------------------------------------------------------------------------------
1 | name: winter.blocks::lang.blocks.button_group.name
2 | description: winter.blocks::lang.blocks.button_group.description
3 | icon: icon-object-group
4 | tags: ["pages"]
5 | fields:
6 | buttons:
7 | label: winter.blocks::lang.blocks.button_group.buttons
8 | span: full
9 | type: blocks
10 | allow:
11 | - button
12 | config:
13 | position:
14 | label: winter.blocks::lang.blocks.button_group.position
15 | span: left
16 | type: balloon-selector
17 | default: "justify-center"
18 | options:
19 | "justify-start": winter.blocks::lang.blocks.button_group.position_left
20 | "justify-center": winter.blocks::lang.blocks.button_group.position_center
21 | "justify-end": winter.blocks::lang.blocks.button_group.position_right
22 | width:
23 | label: winter.blocks::lang.blocks.button_group.width
24 | span: right
25 | type: balloon-selector
26 | default: "w-full"
27 | options:
28 | "w-full": winter.blocks::lang.blocks.button_group.width_full
29 | "w-auto": winter.blocks::lang.blocks.button_group.width_auto
30 | ==
31 |