@maizzle/framework 4.4.3 → 4.4.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maizzle/framework",
3
- "version": "4.4.3",
3
+ "version": "4.4.5",
4
4
  "description": "Maizzle is a framework that helps you quickly build HTML emails with Tailwind CSS.",
5
5
  "license": "MIT",
6
6
  "main": "src/index.js",
@@ -92,7 +92,9 @@ module.exports = {
92
92
 
93
93
  if (buildTemplates) {
94
94
  const templateObjects = Array.isArray(buildTemplates) ? buildTemplates : [buildTemplates]
95
- const fileTypes = get(buildTemplates, 'filetypes', 'html')
95
+ const configFileTypes = get(buildTemplates, 'filetypes', ['html'])
96
+ const fileTypes = Array.isArray(configFileTypes) ? configFileTypes : configFileTypes.split('|')
97
+ const fileTypesPattern = fileTypes.length > 1 ? `{${fileTypes.join(',')}}` : fileTypes[0]
96
98
 
97
99
  templateObjects.forEach(template => {
98
100
  const source = get(template, 'source')
@@ -101,7 +103,7 @@ module.exports = {
101
103
  const sources = source(config)
102
104
 
103
105
  if (Array.isArray(sources)) {
104
- sources.map(s => tailwindConfig.content.files.push(`${s}/**/*.${fileTypes}`))
106
+ sources.map(s => tailwindConfig.content.files.push(`${s}/**/*.${fileTypesPattern}`))
105
107
  } else if (typeof sources === 'string') {
106
108
  tailwindConfig.content.files.push(sources)
107
109
  }
@@ -114,7 +116,7 @@ module.exports = {
114
116
 
115
117
  // Default behavior - directory sources as a string
116
118
  else {
117
- tailwindConfig.content.files.push(`${source}/**/*.${fileTypes}`)
119
+ tailwindConfig.content.files.push(`${source}/**/*.${fileTypesPattern}`)
118
120
  }
119
121
  })
120
122
  }
@@ -6,16 +6,19 @@ const matchHelper = require('posthtml-match-helper')
6
6
  const defaultConfig = require('../generators/posthtml/defaultConfig')
7
7
 
8
8
  module.exports = async (html, config = {}) => {
9
- if (get(config, 'removeInlinedClasses') === false) {
9
+ if (get(config, 'removeInlinedSelectors') === false) {
10
10
  return html
11
11
  }
12
12
 
13
- const posthtmlOptions = merge(defaultConfig, get(config, 'build.posthtml.options', {}))
13
+ const options = {
14
+ posthtml: merge(defaultConfig, get(config, 'build.posthtml.options', {})),
15
+ removeUnusedCSS: config
16
+ }
14
17
 
15
- return posthtml([plugin(posthtmlOptions)]).process(html, posthtmlOptions).then(result => result.html)
18
+ return posthtml([plugin(options)]).process(html, options.posthtml).then(result => result.html)
16
19
  }
17
20
 
18
- const plugin = posthtmlOptions => tree => {
21
+ const plugin = (options = {}) => tree => {
19
22
  const process = node => {
20
23
  // For each style tag...
21
24
  if (node.tag === 'style') {
@@ -41,8 +44,16 @@ const plugin = posthtmlOptions => tree => {
41
44
  }
42
45
 
43
46
  try {
47
+ const safelist = get(options.removeUnusedCSS, 'whitelist', [])
48
+
44
49
  // If we find the selector in the HTML...
45
50
  tree.match(matchHelper(selector), n => {
51
+ // If the selector is safelisted, preserve it
52
+ if (safelist.some(item => item.endsWith(selector) || item.startsWith(selector))) {
53
+ preservedClasses.push(selector)
54
+ return n
55
+ }
56
+
46
57
  const parsedAttrs = parseAttrs(n.attrs)
47
58
  const classAttr = get(parsedAttrs, 'class', [])
48
59
  const styleAttr = get(parsedAttrs, 'style', {})
@@ -64,7 +75,7 @@ const plugin = posthtmlOptions => tree => {
64
75
 
65
76
  // Fix issue with .compose() automatically quoting attributes with no values
66
77
  Object.entries(n.attrs).forEach(([name, value]) => {
67
- if (value === '' && get(posthtmlOptions, 'recognizeNoValueAttribute') === true) {
78
+ if (value === '' && get(options.posthtml, 'recognizeNoValueAttribute') === true) {
68
79
  n.attrs[name] = true
69
80
  }
70
81
  })
@@ -33,10 +33,10 @@ module.exports = async (html, config = {}, direct = false) => {
33
33
  {heads: '{{', tails: '}}'},
34
34
  {heads: '{%', tails: '%}'}
35
35
  ],
36
- whitelist: [...get(config, 'whitelist', []), ...safelist]
36
+ whitelist: get(config, 'whitelist', safelist)
37
37
  }
38
38
 
39
- const options = merge(defaultOptions, get(config, 'removeUnusedCSS', {}))
39
+ const options = merge(defaultOptions, config)
40
40
 
41
41
  /**
42
42
  * Remove possibly inlined selectors, as long as we're not calling