posthtml-component 1.0.0-beta.11 → 1.0.0-beta.13
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 +1 -1
- package/readme.md +1 -1
- package/src/index.js +28 -1
- package/src/process-attributes.js +8 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -109,7 +109,7 @@ See also the `docs-src` folder where you can find more examples. You can run `np
|
|
|
109
109
|
| **push** | `push` | String value for `<push>` tag name. |
|
|
110
110
|
| **stack** | `stack` | String value for `<stack>` tag name. |
|
|
111
111
|
| **propsScriptAttribute** | `props` | String value used as attribute in `<script props>` parsed by the plugin to retrieve props of the component. |
|
|
112
|
-
| **propsContext** | `props` | String value used as object name inside the script to process
|
|
112
|
+
| **propsContext** | `props` | String value used as object name inside the script to process props before passed to the component. |
|
|
113
113
|
| **propsAttribute** | `props` | String value for props attribute to define props as JSON. |
|
|
114
114
|
| **propsSlot** | `props` | String value used to retrieve the props passed to slot via `$slots.slotName.props`. |
|
|
115
115
|
| **expressions** | `{}` | Object to configure `posthtml-expressions`. You can pre-set locals or customize the delimiters for example. |
|
package/src/index.js
CHANGED
|
@@ -10,8 +10,20 @@ const processProps = require('./process-props');
|
|
|
10
10
|
const processAttributes = require('./process-attributes');
|
|
11
11
|
const {processPushes, processStacks} = require('./process-stacks');
|
|
12
12
|
const {setFilledSlots, processSlotContent, processFillContent} = require('./process-slots');
|
|
13
|
+
const each = require('lodash/each');
|
|
14
|
+
const defaults = require('lodash/defaults');
|
|
15
|
+
const assignWith = require('lodash/assignWith');
|
|
13
16
|
const mergeWith = require('lodash/mergeWith');
|
|
14
17
|
const template = require('lodash/template');
|
|
18
|
+
const get = require('lodash/get');
|
|
19
|
+
const has = require('lodash/has');
|
|
20
|
+
const isObjectLike = require('lodash/isObjectLike');
|
|
21
|
+
const isArray = require('lodash/isArray');
|
|
22
|
+
const isEmpty = require('lodash/isEmpty');
|
|
23
|
+
const isBoolean = require('lodash/isBoolean');
|
|
24
|
+
const isUndefined = require('lodash/isUndefined'); // value === undefined
|
|
25
|
+
const isNull = require('lodash/isNull'); // value === null
|
|
26
|
+
const isNil = require('lodash/isNil'); // value == null
|
|
15
27
|
|
|
16
28
|
// const {inspect} = require('util');
|
|
17
29
|
// const debug = true;
|
|
@@ -45,7 +57,22 @@ module.exports = (options = {}) => tree => {
|
|
|
45
57
|
options.plugins = options.plugins || [];
|
|
46
58
|
options.attrsParserRules = options.attrsParserRules || {};
|
|
47
59
|
options.strict = typeof options.strict === 'undefined' ? true : options.strict;
|
|
48
|
-
options.utilities = options.utilities || {
|
|
60
|
+
options.utilities = options.utilities || {
|
|
61
|
+
each,
|
|
62
|
+
defaults,
|
|
63
|
+
assign: assignWith,
|
|
64
|
+
merge: mergeWith,
|
|
65
|
+
template,
|
|
66
|
+
get,
|
|
67
|
+
has,
|
|
68
|
+
isObject: isObjectLike,
|
|
69
|
+
isArray,
|
|
70
|
+
isEmpty,
|
|
71
|
+
isBoolean,
|
|
72
|
+
isUndefined,
|
|
73
|
+
isNull,
|
|
74
|
+
isNil
|
|
75
|
+
};
|
|
49
76
|
|
|
50
77
|
// Merge customizer callback passed to lodash mergeWith
|
|
51
78
|
// for merge attribute `props` and all attributes starting with `merge:`
|
|
@@ -60,5 +60,13 @@ module.exports = (currentNode, attributes, props, options) => {
|
|
|
60
60
|
delete attributes[key];
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
+
// Remove an attribute if value is 'null' or 'undefined'
|
|
64
|
+
// so we can conditionally add an attribute
|
|
65
|
+
each(nodeAttrs, (value, key) => {
|
|
66
|
+
if (['undefined', 'null'].includes(value)) {
|
|
67
|
+
delete nodeAttrs[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
63
71
|
mainNode.attrs = nodeAttrs.compose();
|
|
64
72
|
};
|