Skip to content

Commit 740820f

Browse files
authored
Merge pull request #6 from wbrowar/craft-4/2.0.0
release: 2.0.0
2 parents 481d180 + 033ba52 commit 740820f

File tree

70 files changed

+3686
-3780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3686
-3780
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# NODE ENVIRONMENT
2-
_source/_assets/node_modules/*
2+
_assets/.env
3+
_assets/node_modules/*
34

45
# MISC FILES
56
.cache

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 2.0.0 - 2022-12-05
8+
### Added
9+
- Added field setting to add icons to Little Layout field boxes.
10+
- Added field setting to set the height and width of Little Layout field boxes, using CSS values.
11+
- Added ability to get column and row settings from a field in your Twig templates and GraphQL queries.
12+
13+
### Changed
14+
- Improved performance by refactoring Little Layout field from a Vue app to a Web Component.
15+
- Refactored field settings from a Vue app to a Web Component.
16+
- Changed layout boxes in field from clickable div elements to `button` elements.
17+
- Updated doc blocks and added return types to all PHP files.
18+
- Updated JS bundler to Vite 5.x.
19+
- Bumped NodeJS to Node 20.x.
20+
21+
### Removed
22+
- Removed message that popped up when it was detected that you would need to horizontally scroll.
23+
- Removed Vue and Tailwind CSS as front-end dependencies.
24+
25+
### Fixed
26+
- Update the way the field is saved in order to allow for resaving via the CLI.
27+
- Removed field value change on initialization that caused Craft to think the field was updated before changes were made.
28+
729

830
## 1.2.0 - 2022-05-01
931
### Added

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Little Layout plugin for Craft CMS 4.x
1+
# Little Layout for Craft CMS 4
22

33
A compact, visual way to lay out fields, elements, and Matrix blocks.
44

@@ -11,12 +11,14 @@ This plugin requires Craft CMS 4.0 or later.
1111
To install the plugin, follow these instructions.
1212

1313
1. Open your terminal and go to your Craft project:
14-
15-
cd /path/to/project
14+
```bash
15+
cd /path/to/project
16+
```
1617

1718
2. Then tell Composer to load the plugin:
18-
19-
composer require wbrowar/craft-little-layout
19+
```bash
20+
composer require wbrowar/craft-little-layout
21+
```
2022

2123
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Little Layout.
2224

@@ -44,18 +46,20 @@ Use the Empty Layout setting to determine if authors can clear out the layouts t
4446

4547
The following data can be retrieved in your Twig- or GraphQL-based templates:
4648

47-
| Property | Description |
48-
|---|---|
49-
| **empty** | Determine if field has a value. |
50-
| **gridColumnStart** | Value for CSS Grid’s `grid-column-start` and `grid-column` properties. |
51-
| **gridColumnEnd** | Value for CSS Grid’s `grid-column-end` and `grid-column` properties. |
52-
| **gridRowStart** | Value for CSS Grid’s `grid-row-start` and `grid-row` properties. |
53-
| **gridRowEnd** | Value for CSS Grid’s `grid-row-end` and `grid-row` properties. |
54-
| **gridColumnSpan** | Value for CSS Grid’s `grid-column` property. |
55-
| **gridRowSpan** | Value for CSS Grid’s `grid-row` property. |
56-
| **selectedColumns** | Array of columns selected in the layout field. |
57-
| **selectedRows** | Array of rows selected in the layout field. |
58-
| **selectedCoordinates** | Array of coordinates* selected in the layout field. |
49+
| Property | Description |
50+
|-------------------------|------------------------------------------------------------------------|
51+
| **empty** | Determine if field has a value. |
52+
| **gridColumnStart** | Value for CSS Grid’s `grid-column-start` and `grid-column` properties. |
53+
| **gridColumnEnd** | Value for CSS Grid’s `grid-column-end` and `grid-column` properties. |
54+
| **gridRowStart** | Value for CSS Grid’s `grid-row-start` and `grid-row` properties. |
55+
| **gridRowEnd** | Value for CSS Grid’s `grid-row-end` and `grid-row` properties. |
56+
| **gridColumnSpan** | Value for CSS Grid’s `grid-column` property. |
57+
| **gridRowSpan** | Value for CSS Grid’s `grid-row` property. |
58+
| **selectedColumns** | Array of columns selected in the layout field. |
59+
| **selectedRows** | Array of rows selected in the layout field. |
60+
| **selectedCoordinates** | Array of coordinates* selected in the layout field. |
61+
| **totalColumns** | The columns setting for this field. |
62+
| **totalRows** | The rows setting for this field. |
5963

6064
_*Coordinates are formatted in `'x|y'` format._
6165

@@ -105,7 +109,7 @@ With CSS that looks like this:
105109
If you use a CSS framework, like Tailwind CSS, you could do something like this:
106110

107111
```twig
108-
<div class="col-start-{{ element.fieldHandle.gridColumnStart }} col-span-{{ element.fieldHandle.gridColumnSpan }} row-start-{{ element.fieldHandle.gridRowStart }} row-span-{{ element.fieldHandle.gridRowSpan }}"></div>
112+
<div class="col-start-[{{ element.fieldHandle.gridColumnStart }}] col-span-[{{ element.fieldHandle.gridColumnSpan }}] row-start-[{{ element.fieldHandle.gridRowStart }}] row-span-[{{ element.fieldHandle.gridRowSpan }}]"></div>
109113
```
110114

111115
If your Twig template files are included in your Tailwind confguration’s `content` patterns, you may prefer to preserve full class names using logic and a lookup table:

_assets/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20

_assets/.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"arrowParens": "always",
3+
"printWidth": 120,
4+
"semi": false,
5+
"singleQuote": true,
6+
"tabWidth": 2,
7+
"trailingComma": "es5"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { it } from 'vitest'
2+
// import { LittleLayoutField } from "./LittleLayoutField";
3+
4+
it('test method', () => {
5+
// const wrapper = new LittleLayoutField();
6+
// expect(wrapper.testMethod()).toBe('hello');
7+
// expect(wrapper.testMethod('hey')).toBe('hey');
8+
})
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
import { html, LitElement } from 'lit'
2+
import { customElement, property, state } from 'lit/decorators.js'
3+
import { log, table } from '../utils/console'
4+
import type { SelectionMode } from '../types'
5+
import { BoxIcons } from '../types'
6+
7+
@customElement('little-layout-field')
8+
export class LittleLayoutField extends LitElement {
9+
/**
10+
* ===========================================================================
11+
* PROPS
12+
* ===========================================================================
13+
*/
14+
/**
15+
* Pass-through prop based on field setting.
16+
*/
17+
@property({ attribute: 'box-icons', type: Object })
18+
boxIcons: BoxIcons = {}
19+
20+
/**
21+
* Pass-through prop based on field setting.
22+
*/
23+
@property({ type: Boolean })
24+
clearable = false
25+
26+
/**
27+
* The default value of the field, based on the field’s current value or the default set in field settings.
28+
*/
29+
@property({ attribute: 'default-value' })
30+
defaultValue = ''
31+
32+
/**
33+
* Pass-through prop based on field setting.
34+
*/
35+
@property({ type: Boolean })
36+
editable = false
37+
38+
/**
39+
* The ID attribute for the input field.
40+
*/
41+
@property({ attribute: 'field-id' })
42+
fieldId = ''
43+
44+
/**
45+
* The name attribute for the input field.
46+
*/
47+
@property({ attribute: 'field-name' })
48+
fieldName = ''
49+
50+
/**
51+
* Pass-through prop based on field setting.
52+
*/
53+
@property({ attribute: 'layout-cols', type: Number })
54+
layoutCols = 1
55+
56+
/**
57+
* Pass-through prop based on field setting.
58+
*/
59+
@property({ attribute: 'layout-rows', type: Number })
60+
layoutRows = 1
61+
62+
/**
63+
* Pass-through prop based on field setting.
64+
*/
65+
@property({ attribute: 'selection-mode' })
66+
selectionMode: SelectionMode = 'box'
67+
68+
/**
69+
* =========================================================================
70+
* STATE
71+
* =========================================================================
72+
*/
73+
/**
74+
* The value attribute for the input field. This is updated via an event from the child component.
75+
*/
76+
@state()
77+
private _fieldValue = ''
78+
79+
/**
80+
* =========================================================================
81+
* EVENTS
82+
* =========================================================================
83+
*/
84+
/**
85+
* Handles the `@value-updated` event. Sets the `_fieldValue` passed in from the event.
86+
*/
87+
private _fieldValueListener(e: CustomEvent) {
88+
this._fieldValue = e.detail.fieldValue
89+
this._setInputValueFromFieldValue()
90+
}
91+
92+
/**
93+
* =========================================================================
94+
* METHODS
95+
* =========================================================================
96+
*/
97+
/**
98+
* Sets `_fieldValue` from the value of the input.
99+
*/
100+
private _getFieldValueFromInput() {
101+
const littleLayoutInput = this.querySelector('input')
102+
103+
if (littleLayoutInput) {
104+
this._fieldValue = littleLayoutInput.value
105+
}
106+
}
107+
108+
/**
109+
* Sets the value of the input from `_fieldValue`.
110+
*/
111+
private _setInputValueFromFieldValue() {
112+
const littleLayoutInput = this.querySelector('input')
113+
114+
if (littleLayoutInput) {
115+
littleLayoutInput.value = this._fieldValue
116+
}
117+
}
118+
119+
/**
120+
* =========================================================================
121+
* LIFECYCLE
122+
* =========================================================================
123+
*/
124+
connectedCallback() {
125+
super.connectedCallback()
126+
127+
this._getFieldValueFromInput()
128+
129+
const littleLayoutInput = this.querySelector('input')
130+
131+
if (littleLayoutInput) {
132+
littleLayoutInput.addEventListener('change', this._getFieldValueFromInput)
133+
littleLayoutInput.addEventListener('input', this._getFieldValueFromInput)
134+
}
135+
136+
log('Little Layout: connected')
137+
table({
138+
clearable: this.clearable,
139+
layoutCols: this.layoutCols,
140+
defaultValue: this.defaultValue,
141+
editable: this.editable,
142+
fieldId: this.fieldId,
143+
fieldName: this.fieldName,
144+
layoutRows: this.layoutRows,
145+
selectionMode: this.selectionMode,
146+
})
147+
}
148+
149+
disconnectedCallback() {
150+
super.disconnectedCallback()
151+
152+
const littleLayoutInput = this.querySelector('input')
153+
154+
if (littleLayoutInput) {
155+
littleLayoutInput.removeEventListener('change', this._getFieldValueFromInput)
156+
littleLayoutInput.removeEventListener('input', this._getFieldValueFromInput)
157+
}
158+
}
159+
160+
render() {
161+
return html`
162+
<little-layout-field-control
163+
?clearable="${this.clearable}"
164+
?editable="${this.editable}"
165+
box-icons="${JSON.stringify(this.boxIcons)}"
166+
field-default="${this._fieldValue}"
167+
layout-cols="${this.layoutCols}"
168+
layout-rows="${this.layoutRows}"
169+
selection-mode="${this.selectionMode}"
170+
@value-updated="${this._fieldValueListener}"
171+
></little-layout-field-control>
172+
`
173+
}
174+
175+
/**
176+
* Changes the render mode for this component from shadow DOM to light DOM.
177+
*/
178+
protected createRenderRoot() {
179+
return this
180+
}
181+
}
182+
183+
declare global {
184+
interface HTMLElementTagNameMap {
185+
'little-layout-field': LittleLayoutField
186+
}
187+
}

0 commit comments

Comments
 (0)