Skip to content
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

DEP Upgrade frontend build stack #88

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
[{*.yml,*.js,*.scss,package.json}]
indent_size = 2
indent_style = space

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@silverstripe/eslint-config/.eslintrc');
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/**/*.js.map
/**/*.css.map
/vendor/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
13 changes: 0 additions & 13 deletions client/css/multivaluefield.css

This file was deleted.

1 change: 1 addition & 0 deletions client/dist/js/multivaluefield.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/dist/styles/multivaluefield.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 0 additions & 69 deletions client/javascript/multivaluefield.js

This file was deleted.

75 changes: 75 additions & 0 deletions client/src/js/multivaluefield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* global jQuery */
jQuery(($) => {
function addNewField() {
const self = $(this);
const val = self.val();
const keySep = '__';

// check to see if the one after us is there already - if so, we don't need a new one
const li = $(this).closest('li').next('li');

if (!val) {
// lets also clean up if need be
const nextText = li.find('input.mventryfield');
let detach = true;

nextText.each(function () {
if ($(this) && $(this).val() && $(this).val().length > 0) {
detach = false;
}
});

if (detach) {
li.detach();
}
} else {
if (li.length) {
return;
}

const append = self.closest('li')
.clone()
.find('.has-chzn')
.show()
.removeClass('')
.data('chosen', null)
.end()
.find('.chzn-container')
.remove()
.end();

// Assign the new inputs a unique ID, so that chosen picks up
// the correct container.
append.find('input, select, textarea').val('').each(function () {
let pos = this.id.lastIndexOf(keySep);
if (pos !== -1) {
pos += keySep.length;

const maxId = parseInt(this.id.substr(pos), 10);
const nextId = maxId + 1;

this.id = this.id.substr(0, pos) + nextId; // nextId auto-converted to string here
}
});

append.appendTo(self.parents('ul.multivaluefieldlist'));
}

$(this).trigger('multiValueFieldAdded');
}

$(document).on('keyup', '.mventryfield', addNewField);
$(document).on('change', '.mventryfield:not(input)', addNewField);

if ($.fn.sortable) {
if ($.entwine) {
$('ul.multivaluefieldlist').entwine({
onmatch() {
$(this).sortable();
}
});
} else {
$('ul.multivaluefieldlist').sortable();
}
}
});
37 changes: 37 additions & 0 deletions client/src/styles/multivaluefield.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ul.multivaluefieldlist {
margin: 0px;
padding: 0px;
}

.multivaluefieldlist > li {
margin-bottom: 4px;
min-width: 250px;
list-style-type: none;
}

.multivaluefieldlist > li::after {
content: '↕';
cursor: pointer;
}

.multivaluefieldlist > li:last-child {
margin-bottom: 0;
}

.mventryfield {
max-width: 200px !important;
display: inline;
}

textarea.mventryfield {
max-width: none !important;
vertical-align: top;
}

.multivaluefieldlist .chosen-container {
max-width: 90% !important;
}

.field .multivaluefieldlist input.text, .field .multivaluefieldlist select {
display: inline;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"extra": {
"expose": [
"client"
"client/dist"
],
"installer-name": "multivaluefield"
},
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "multivaluefield",
"engines": {
"node": ">=18.x"
},
"scripts": {
"build": "yarn && yarn lint && rm -rf client/dist/* && NODE_ENV=production webpack --mode production --bail --progress",
"dev": "NODE_ENV=development webpack --progress",
"watch": "NODE_ENV=development webpack --watch --progress",
"lint": "eslint client/src && sass-lint client/src"
},
"dependencies": {
},
"devDependencies": {
"@silverstripe/eslint-config": "^1.0.0-alpha6",
"@silverstripe/webpack-config": "^2.0.0-alpha5",
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0"
},
"resolutions": {
"colors": "1.4.0"
},
"browserslist": [
"defaults"
]
}
7 changes: 2 additions & 5 deletions src/Fields/KeyValueField.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ public function __construct($name, $title = null, $sourceKeys = [], $sourceValue

public function Field($properties = [])
{
if (Controller::curr() instanceof ContentController) {
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
}
Comment on lines -83 to -85
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not stored there anymore - and even if it was, we shouldn't just inject jQuery into peoples' projects like this

Requirements::javascript('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css');
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$nameKey = $this->name.'[key][]';
$nameVal = $this->name.'[val][]';
Expand Down
7 changes: 2 additions & 5 deletions src/Fields/MultiValueDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ public function setSource(array $source)

public function Field($properties = [])
{
if (Controller::curr() instanceof ContentController) {
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
}
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css');
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';
$fields = [];
Expand Down
7 changes: 2 additions & 5 deletions src/Fields/MultiValueListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ public function __construct($name, $title = null, $source = [], $value = null)

public function Field($properties = [])
{
if (Controller::curr() instanceof ContentController) {
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
}
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css');
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';

Expand Down
7 changes: 2 additions & 5 deletions src/Fields/MultiValueTextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ class MultiValueTextField extends FormField

public function Field($properties = [])
{
if (Controller::curr() instanceof ContentController) {
Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js');
}
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css');
Requirements::javascript('symbiote/silverstripe-multivaluefield: client/dist/js/multivaluefield.js');
Requirements::css('symbiote/silverstripe-multivaluefield: client/dist/styles/multivaluefield.css');

$name = $this->name.'[]';
$fields = [];
Expand Down
34 changes: 34 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const Path = require('path');
const { JavascriptWebpackConfig, CssWebpackConfig } = require('@silverstripe/webpack-config');

const PATHS = {
ROOT: Path.resolve(),
SRC: Path.resolve('client/src'),
DIST: Path.resolve('client/dist'),
};

// Main JS bundle
const jsConfig = new JavascriptWebpackConfig('js', PATHS, 'symbiote/silverstripe-multivaluefield')
.setEntry({
multivaluefield: `${PATHS.SRC}/js/multivaluefield.js`
})
.getConfig();
// Tell webpack that jquery is externally accessible, but don't include default externals as this can be used on the frontend
jsConfig.externals = {
jquery: 'jQuery'
};

const config = [
jsConfig,
// sass to css
new CssWebpackConfig('css', PATHS)
.setEntry({
multivaluefield: `${PATHS.SRC}/styles/multivaluefield.scss`
})
.getConfig(),
];

// Use WEBPACK_CHILD=js or WEBPACK_CHILD=css env var to run a single config
module.exports = (process.env.WEBPACK_CHILD)
? config.find((entry) => entry.name === process.env.WEBPACK_CHILD)
: config;
Loading