@pushword/js-helper 0.0.117 → 0.0.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ Some js helpers for Pushword front end.
5
5
  [![Latest Version](https://img.shields.io/github/tag/pushword/pushword.svg?style=flat&label=release)](https://github.com/Pushword/Pushword/tags)
6
6
  [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE)
7
7
  [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/Pushword/Pushword/run-tests.yml?branch=main)](https://github.com/Pushword/Pushword/actions)
8
- [![Quality Score](https://img.shields.io/scrutinizer/g/pushword/pushword.svg?style=flat)](https://scrutinizer-ci.com/g/pushword/pushword)
8
+
9
9
  [![Code Coverage](https://codecov.io/gh/Pushword/Pushword/branch/main/graph/badge.svg)](https://codecov.io/gh/Pushword/Pushword/tree/main)
10
10
  [![Type Coverage](https://shepherd.dev/github/pushword/pushword/coverage.svg)](https://shepherd.dev/github/pushword/pushword)
11
11
  [![Total Downloads](https://img.shields.io/packagist/dt/pushword/core.svg?style=flat)](https://packagist.org/packages/pushword/core)
@@ -27,6 +27,6 @@ If you're interested in contributing to Pushword, please read our [contributing
27
27
 
28
28
  The MIT License (MIT). Please see [License File](https://pushword.piedweb.com/license#license) for more information.
29
29
 
30
- <p align="center"><a href="https://dev.piedweb.com" rel="dofollow">
30
+ <p align="center"><a href="https://dev.piedweb.com">
31
31
  <img src="https://raw.githubusercontent.com/Pushword/Pushword/f5021f4c5d5d3ab3f2858ec2e4bdd70818806c6a/packages/admin/src/Resources/assets/logo.svg" width="200" height="200" alt="PHP Packages Open Source" />
32
32
  </a></p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushword/js-helper",
3
- "version": "0.0.117",
3
+ "version": "0.0.119",
4
4
  "description": "Pushword front end helpers. ",
5
5
  "author": "Robin@PiedWeb <contact@piedweb.com>",
6
6
  "license": "MIT",
@@ -9,13 +9,12 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "140.css": "^1.0.1",
12
- "@babel/core": "^7.23",
13
- "@babel/preset-env": "^7.22.20",
14
- "@symfony/webpack-encore": "^4.6",
12
+ "@babel/core": "^7.24",
13
+ "@babel/preset-env": "^7.22",
14
+ "@symfony/webpack-encore": "^5",
15
15
  "@tailwindcss/aspect-ratio": "^0.4",
16
16
  "@tailwindcss/forms": "^0.5",
17
17
  "@tailwindcss/typography": "^0.5",
18
- "ace-builds": "^1.36",
19
18
  "autoprefixer": "^10.4",
20
19
  "babel-preset-stage-2": "^6.24.1",
21
20
  "codemirror": "^6.0",
@@ -25,12 +24,12 @@
25
24
  "fslightbox": "^3.2.2",
26
25
  "postcss": "^8.4",
27
26
  "postcss-import": "^16",
28
- "postcss-loader": "^7",
27
+ "postcss-loader": "^8",
29
28
  "sass": "^1.68",
30
29
  "sass-loader": "^16",
31
30
  "simple-jekyll-search": "^1.9.1",
32
31
  "tailwindcss": "^3",
33
- "tailwindcss-animated": "^1.1",
32
+ "tailwindcss-animated": "^2",
34
33
  "tailwindcss-hero-patterns": "^0.1",
35
34
  "tailwindcss-multi-column": "^1.0.2",
36
35
  "webpack": "^5.94",
package/src/encore.js CHANGED
@@ -2,6 +2,7 @@ const WatchExternalFilesPlugin = require('webpack-watch-files-plugin').default
2
2
  const tailwindcss = require('tailwindcss')
3
3
  const postcssImport = require('postcss-import')
4
4
  const autoprefixer = require('autoprefixer')
5
+ const Encore = require('@symfony/webpack-encore')
5
6
 
6
7
  function getFilesToWatch(basePath = './..') {
7
8
  return [
@@ -22,6 +23,10 @@ function getTailwindConfig(watchFiles = null) {
22
23
  return tailwindConfig
23
24
  }
24
25
 
26
+ /**
27
+ *
28
+ * @param {Encore} Encore
29
+ */
25
30
  function getEncore(
26
31
  Encore,
27
32
  watchFiles = null, // default: getFilesToWatch()
@@ -32,6 +37,7 @@ function getEncore(
32
37
  filesToCopy = null, // default :: ... from: /favicons. ...
33
38
  entries = null, // [{ name: 'app', file: '/node_modules/@pushword/js-helper/src/app.js' }];
34
39
  styleEntries = null, // [{ name: 'style', file: '/node_modules/@pushword/js-helper/src/app.css' }];
40
+ isLegacy = false,
35
41
  ) {
36
42
  if (watchFiles === null) {
37
43
  watchFiles = getFilesToWatch()
@@ -41,13 +47,14 @@ function getEncore(
41
47
  tailwindConfig = getTailwindConfig(watchFiles)
42
48
  }
43
49
 
50
+ const jsAppName = 'app' + (isLegacy ? '-legacy' : '')
44
51
  if (entries === null) {
45
- entries = [{ name: 'app', file: __dirname + '/app.js' }]
52
+ entries = [{ name: jsAppName, file: __dirname + '/app.js' }]
46
53
  } else if (typeof entries === 'string') {
47
- entries = [{ name: 'app', file: entries }]
54
+ entries = [{ name: jsAppName, file: entries }]
48
55
  }
49
56
 
50
- if (styleEntries === null) {
57
+ if (styleEntries === null && !isLegacy) {
51
58
  styleEntries = [{ name: 'style', file: __dirname + '/app.css' }]
52
59
  } else if (typeof styleEntries === 'string') {
53
60
  styleEntries = [{ name: 'style', file: styleEntries }]
@@ -59,7 +66,6 @@ function getEncore(
59
66
  Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev')
60
67
  .setOutputPath(outputPath)
61
68
  .setPublicPath(publicPath)
62
- .cleanupOutputBeforeBuild()
63
69
  .enableSassLoader()
64
70
  .enableSourceMaps(false)
65
71
  .enableVersioning(false)
@@ -75,7 +81,7 @@ function getEncore(
75
81
  })
76
82
  .disableSingleRuntimeChunk()
77
83
 
78
- if (filesToCopy === null) {
84
+ if (filesToCopy === null && !isLegacy) {
79
85
  filesToCopy = [
80
86
  {
81
87
  from: './favicons',
@@ -84,9 +90,10 @@ function getEncore(
84
90
  ]
85
91
  }
86
92
 
87
- filesToCopy.forEach(function (toCopy) {
88
- Encore.copyFiles(toCopy)
89
- })
93
+ if (filesToCopy)
94
+ filesToCopy.forEach(function (toCopy) {
95
+ Encore.copyFiles(toCopy)
96
+ })
90
97
 
91
98
  if (manifestKeyPrefix !== null) Encore.setManifestKeyPrefix(manifestKeyPrefix)
92
99
 
@@ -94,9 +101,26 @@ function getEncore(
94
101
  Encore.addEntry(entry.name, entry.file)
95
102
  })
96
103
 
97
- styleEntries.forEach(function (entry) {
98
- Encore.addStyleEntry(entry.name, entry.file)
99
- })
104
+ if (styleEntries)
105
+ styleEntries.forEach(function (entry) {
106
+ Encore.addStyleEntry(entry.name, entry.file)
107
+ })
108
+
109
+ //if (!isLegacy) Encore.cleanupOutputBeforeBuild()
110
+
111
+ if (!isLegacy) {
112
+ Encore.configureBabelPresetEnv((config) => {
113
+ config.targets = {
114
+ browsers: ['Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
115
+ }
116
+ })
117
+ } else {
118
+ Encore.configureBabelPresetEnv((config) => {
119
+ config.targets = {
120
+ browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'],
121
+ }
122
+ })
123
+ }
100
124
 
101
125
  return Encore
102
126
  }
package/src/helpers.js CHANGED
@@ -21,18 +21,18 @@ import 'regenerator-runtime/runtime'
21
21
  *
22
22
  * @param {string} attribute
23
23
  */
24
- export function liveBlock(liveBlockAttribute = 'data-live', liveFormSelector = '.live-form') {
24
+ export function liveBlock(liveBlockAttribute = 'live', liveFormSelector = '.live-form') {
25
25
  var btnToBlock = function (event, btn) {
26
- const liveBlockUrl = btn.getAttribute('src-' + liveBlockAttribute)
26
+ const liveBlockUrl = btn.getAttribute('data-src-' + liveBlockAttribute)
27
27
  if (btn.hasAttribute('data-target') && btn.getAttribute('data-target') == 'parent') {
28
28
  btn = btn.parentElement ?? btn
29
29
  }
30
- btn.setAttribute(liveBlockAttribute, liveBlockUrl)
30
+ btn.setAttribute('data-' + liveBlockAttribute, liveBlockUrl)
31
31
  getLiveBlock(btn)
32
32
  }
33
33
 
34
34
  var getLiveBlock = function (item) {
35
- var url = item.getAttribute(liveBlockAttribute)
35
+ var url = item.getAttribute('data-' + liveBlockAttribute)
36
36
  url = url.startsWith('e:') ? convertShortchutForLink(rot13ToText(url.substring(2))) : url
37
37
  fetch(url, {
38
38
  //headers: { "Content-Type": "application/json", Accept: "text/plain" },
@@ -43,7 +43,7 @@ export function liveBlock(liveBlockAttribute = 'data-live', liveFormSelector = '
43
43
  return response.text()
44
44
  })
45
45
  .then(function (body) {
46
- item.removeAttribute(liveBlockAttribute)
46
+ item.removeAttribute('data-' + liveBlockAttribute)
47
47
  item.outerHTML = body
48
48
  })
49
49
  .then(function () {
@@ -94,12 +94,12 @@ export function liveBlock(liveBlockAttribute = 'data-live', liveFormSelector = '
94
94
  }
95
95
 
96
96
  // Listen data-live
97
- document.querySelectorAll('[' + liveBlockAttribute + ']').forEach((item) => {
97
+ document.querySelectorAll('[' + 'data-' + liveBlockAttribute + ']').forEach((item) => {
98
98
  getLiveBlock(item)
99
99
  })
100
100
 
101
- // Listen button src-data-live
102
- document.querySelectorAll('[src-' + liveBlockAttribute + ']').forEach((item) => {
101
+ // Listen button src-data-live / data-src-live
102
+ document.querySelectorAll('[' + 'data-src' + liveBlockAttribute + ']').forEach((item) => {
103
103
  item.addEventListener('click', (event) => {
104
104
  if (item.tagName == 'BUTTON') {
105
105
  item.innerHTML = spinner
@@ -124,7 +124,7 @@ export function liveBlock(liveBlockAttribute = 'data-live', liveFormSelector = '
124
124
  * Block to replace Watcher
125
125
  * On $event on element find via $attribute, set attribute's content in element.innerHTML
126
126
  */
127
- export function replaceOn(attribute = 'replaceBy', eventName = 'click') {
127
+ export function replaceOn(attribute = 'data-replaceBy', eventName = 'click') {
128
128
  var loadVideo = function (element) {
129
129
  var content = element.getAttribute(attribute)
130
130
  if (element.classList.contains('hero-banner-overlay-lg') && element.querySelector('picture') && window.innerWidth < 992) {
@@ -213,6 +213,11 @@ export function addClassForNormalUser(attribute = 'data-acinb') {
213
213
  if (window.location.hash) {
214
214
  const targetElement = document.querySelector(window.location.hash)
215
215
  if (targetElement) {
216
+ // open show more block if exists
217
+ const showMoreTarget = targetElement.closest('.show-more')
218
+ if (showMoreTarget) {
219
+ showMoreTarget.querySelector('.show-more-btn label').click()
220
+ }
216
221
  targetElement.scrollIntoView({
217
222
  behavior: 'smooth',
218
223
  })
@@ -366,10 +371,10 @@ export function testWebPSupport() {
366
371
  */
367
372
  export function convertImageLinkToWebPLink() {
368
373
  var switchToWebP = function () {
369
- ;[].forEach.call(document.querySelectorAll('a[dwl]'), function (element) {
370
- var href = responsiveImage(element.getAttribute('dwl'))
374
+ ;[].forEach.call(document.querySelectorAll('a[data-dwl]'), function (element) {
375
+ var href = responsiveImage(element.getAttribute('data-dwl'))
371
376
  element.setAttribute('href', href)
372
- element.removeAttribute('dwl')
377
+ element.removeAttribute('data-dwl')
373
378
  })
374
379
  }
375
380