posthtml-component 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (63) hide show
  1. package/package.json +1 -1
  2. package/readme.md +1 -1
  3. package/src/index.js +28 -16
  4. package/src/slots.js +10 -10
  5. package/.c8rc +0 -3
  6. package/.clintonrc.json +0 -21
  7. package/.editorconfig +0 -19
  8. package/.huskyrc +0 -7
  9. package/.idea/posthtml-components.iml +0 -8
  10. package/.lintstagedrc +0 -4
  11. package/.nycrc +0 -4
  12. package/changelog.md +0 -13
  13. package/docs/docs.html +0 -1514
  14. package/docs/index.html +0 -136
  15. package/docs/test.html +0 -234
  16. package/test/templates/components/child.html +0 -41
  17. package/test/templates/components/component-append-prepend.html +0 -1
  18. package/test/templates/components/component-default-yield.html +0 -1
  19. package/test/templates/components/component-locals-json-and-string.html +0 -18
  20. package/test/templates/components/component-locals-type.html +0 -36
  21. package/test/templates/components/component-locals.html +0 -7
  22. package/test/templates/components/component-mapped-attributes.html +0 -7
  23. package/test/templates/components/component-mapped-attributes2.html +0 -7
  24. package/test/templates/components/component-mapped-attributes3.html +0 -7
  25. package/test/templates/components/component-multiple-slot.html +0 -1
  26. package/test/templates/components/component-with-include.html +0 -1
  27. package/test/templates/components/component-with-module.html +0 -1
  28. package/test/templates/components/component-without-elements.html +0 -1
  29. package/test/templates/components/component.html +0 -1
  30. package/test/templates/components/form/index.html +0 -1
  31. package/test/templates/components/included-file.html +0 -1
  32. package/test/templates/components/modal.html +0 -1
  33. package/test/templates/components/module-with-extend.html +0 -1
  34. package/test/templates/components/module.html +0 -1
  35. package/test/templates/components/nested-one-slot.html +0 -5
  36. package/test/templates/components/nested-one.html +0 -1
  37. package/test/templates/components/nested-three.html +0 -1
  38. package/test/templates/components/nested-two-slot.html +0 -5
  39. package/test/templates/components/nested-two.html +0 -1
  40. package/test/templates/components/parent.html +0 -42
  41. package/test/templates/components/script-locals.html +0 -9
  42. package/test/templates/custom/dark/components/button.html +0 -1
  43. package/test/templates/custom/dark/components/label/index.html +0 -1
  44. package/test/templates/dark/components/button.html +0 -1
  45. package/test/templates/dark/components/label/index.html +0 -1
  46. package/test/templates/dark/layouts/base.html +0 -1
  47. package/test/templates/layouts/base-locals.html +0 -6
  48. package/test/templates/layouts/base-render-slots-locals.html +0 -8
  49. package/test/templates/layouts/base.html +0 -8
  50. package/test/templates/layouts/extend-with-module.html +0 -7
  51. package/test/templates/layouts/extend.html +0 -7
  52. package/test/templates/layouts/playground.html +0 -1
  53. package/test/templates/layouts/slot-condition.html +0 -8
  54. package/test/templates/light/components/button.html +0 -1
  55. package/test/templates/light/layouts/base.html +0 -1
  56. package/test/test-attributes.js +0 -42
  57. package/test/test-errors.js +0 -60
  58. package/test/test-locals.js +0 -74
  59. package/test/test-nested.js +0 -24
  60. package/test/test-plugins.js +0 -52
  61. package/test/test-slots.js +0 -85
  62. package/test/test-x-tag.js +0 -69
  63. package/xo.config.js +0 -15
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthtml-component",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "PostHTML Components Blade-like with slots, attributes as props and custom tag",
5
5
  "license": "MIT",
6
6
  "repository": "thewebartisan7/posthtml-components",
package/readme.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <div align="center">
6
6
  <img width="300" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg">
7
7
  <h1>PostHTML Components </h1>
8
- <p>HTML-friendly syntax component with slots, attributes as locals and more!</p>
8
+ <p>A PostHTML plugin for create components with HTML-friendly syntax inspired by Laravel Blade. Slots, stack/push, props, custom tag and much more.</p>
9
9
  </div>
10
10
 
11
11
  ## Installation
package/src/index.js CHANGED
@@ -103,7 +103,7 @@ module.exports = (options = {}) => tree => {
103
103
  function processTree(options) {
104
104
  const filledSlots = {};
105
105
 
106
- // let processCounter = 0;
106
+ let processCounter = 0;
107
107
 
108
108
  return function (tree) {
109
109
  if (options.plugins.length > 0) {
@@ -115,31 +115,21 @@ function processTree(options) {
115
115
  currentNode.attrs = {};
116
116
  }
117
117
 
118
- const componentFile = currentNode.attrs[options.attribute] || findPathFromTag(currentNode.tag, options);
118
+ const componentPath = getComponentPath(currentNode, options);
119
119
 
120
- if (!componentFile) {
120
+ if (!componentPath) {
121
121
  return currentNode;
122
122
  }
123
123
 
124
- const componentPath = path.isAbsolute(componentFile) && !currentNode.attrs[options.attribute] ?
125
- componentFile :
126
- path.join(options.root, componentFile);
127
-
128
- // Check if file exist only when not using x-tag
129
- if (currentNode.attrs[options.attribute] && !existsSync(componentPath)) {
130
- if (options.strict) {
131
- throw new Error(`[components] The component was not found in ${componentPath}.`);
132
- } else {
133
- return currentNode;
134
- }
135
- }
124
+ console.log(`${++processCounter}) Processing component ${componentPath}`);
136
125
 
137
- // console.log(`${++processCounter}) Processing component ${componentPath}`);
126
+ // log(currentNode, 'currentNode');
138
127
 
139
128
  let nextNode = parser(readFileSync(componentPath, 'utf8'));
140
129
 
141
130
  // Set filled slots
142
131
  setFilledSlots(currentNode, filledSlots, options);
132
+ // setFilledSlots(nextNode, filledSlots, options);
143
133
 
144
134
  // Reset previous locals with passed global and keep aware locals
145
135
  options.expressions.locals = {...options.locals, ...options.aware};
@@ -161,6 +151,8 @@ function processTree(options) {
161
151
  return currentNode.content || nextNode.content;
162
152
  });
163
153
 
154
+ nextNode = processTree(options)(nextNode);
155
+
164
156
  // Process <fill> tags
165
157
  processFillContent(nextNode, filledSlots, options);
166
158
 
@@ -190,6 +182,26 @@ function processTree(options) {
190
182
  };
191
183
  }
192
184
 
185
+ function getComponentPath(currentNode, options) {
186
+ const componentFile = currentNode.attrs[options.attribute];
187
+
188
+ if (componentFile) {
189
+ const componentPath = path.join(options.root, componentFile);
190
+
191
+ if (!existsSync(componentPath)) {
192
+ if (options.strict) {
193
+ throw new Error(`[components] The component was not found in ${componentPath}.`);
194
+ } else {
195
+ return false;
196
+ }
197
+ }
198
+
199
+ return componentPath;
200
+ }
201
+
202
+ return findPathFromTag(currentNode.tag, options);
203
+ }
204
+
193
205
  function applyPluginsToTree(tree, plugins) {
194
206
  return plugins.reduce((tree, plugin) => {
195
207
  tree = plugin(tree);
package/src/slots.js CHANGED
@@ -21,7 +21,7 @@ function setFilledSlots(currentNode, filledSlots, {fill, slotSeparator}) {
21
21
 
22
22
  const name = fillNode.tag.split(slotSeparator)[1];
23
23
 
24
- const locals = omit(fillNode.attrs, [name, 'type', 'append', 'prepend', 'aware']);
24
+ const locals = omit(fillNode.attrs, ['append', 'prepend', 'aware']);
25
25
 
26
26
  if (locals) {
27
27
  each(locals, (value, key, attrs) => {
@@ -58,10 +58,6 @@ function processFillContent(tree, filledSlots, {fill, slotSeparator}) {
58
58
  match.call(tree, {tag: fill}, fillNode => {
59
59
  const name = fillNode.tag.split(slotSeparator)[1];
60
60
 
61
- if (!filledSlots[name]) {
62
- filledSlots[name] = {};
63
- }
64
-
65
61
  filledSlots[name].tag = fillNode.tag;
66
62
  filledSlots[name].attrs = fillNode.attrs;
67
63
  filledSlots[name].content = fillNode.content;
@@ -90,17 +86,21 @@ function processSlotContent(tree, filledSlots, {slot, slotSeparator}) {
90
86
 
91
87
  slotNode.tag = false;
92
88
 
93
- if (filledSlots[name]?.rendered) {
89
+ if (!filledSlots[name]) {
90
+ return slotNode;
91
+ }
92
+
93
+ if (filledSlots[name].rendered) {
94
94
  slotNode.content = null;
95
- } else if (slotNode.content && filledSlots[name]?.attrs && (typeof filledSlots[name]?.attrs.append !== 'undefined' || typeof filledSlots[name]?.attrs.prepend !== 'undefined')) {
96
- slotNode.content = typeof filledSlots[name]?.attrs.append === 'undefined' ? filledSlots[name]?.content.concat(slotNode.content) : slotNode.content.concat(filledSlots[name]?.content);
95
+ } else if (slotNode.content && filledSlots[name].attrs && (typeof filledSlots[name].attrs.append !== 'undefined' || typeof filledSlots[name].attrs.prepend !== 'undefined')) {
96
+ slotNode.content = typeof filledSlots[name].attrs.append === 'undefined' ? filledSlots[name].content.concat(slotNode.content) : slotNode.content.concat(filledSlots[name].content);
97
97
  } else {
98
- slotNode.content = filledSlots[name]?.content;
98
+ slotNode.content = filledSlots[name].content;
99
99
  }
100
100
 
101
101
  // Set rendered to true so a slot can be output only once,
102
102
  // when not present "aware" attribute
103
- if (filledSlots[name] && (!filledSlots[name]?.attrs || typeof filledSlots[name].attrs.aware === 'undefined')) {
103
+ if (filledSlots[name] && (!filledSlots[name].attrs || typeof filledSlots[name].attrs.aware === 'undefined')) {
104
104
  filledSlots[name].rendered = true;
105
105
  }
106
106
 
package/.c8rc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "reporter": ["lcov", "text"]
3
- }
package/.clintonrc.json DELETED
@@ -1,21 +0,0 @@
1
- {
2
- "ignores": [
3
- "test/**",
4
- "tmp/**",
5
- "src/**",
6
- "lib/**",
7
- "examples/**",
8
- "docs/**",
9
- ".idea/**",
10
- "*.{html,jpg}",
11
- "cache.json"
12
- ],
13
- "rules": {
14
- "pkg-main": "off",
15
- "cli": "off",
16
- "xo": "off",
17
- "ava": "off",
18
- "use-travis": "off",
19
- "pkg-schema": "off"
20
- }
21
- }
package/.editorconfig DELETED
@@ -1,19 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = space
5
- indent_size = 2
6
- end_of_line = lf
7
- charset = utf-8
8
- quote_type = single
9
- trim_trailing_whitespace = true
10
- insert_final_newline = true
11
-
12
- [{package.json,*.yml,*.jade,*.pss,*.css,*.js,*.md,.*,*.ts}]
13
- indent_size = 2
14
-
15
- [{changelog.md,.*}]
16
- insert_final_newline = false
17
-
18
- [*.md]
19
- trim_trailing_whitespace = false
package/.huskyrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "hooks": {
3
- "pre-push": "npm t",
4
- "pre-commit": "clinton && lint-staged",
5
- "commit-msg": "commitlint --extends=@commitlint/config-angular -e"
6
- }
7
- }
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
package/.lintstagedrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "{src,test}/**/*.js": "xo",
3
- "*.md": "xo"
4
- }
package/.nycrc DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "reporter": ["lcov", "text"],
3
- "extension": [".js"]
4
- }
package/changelog.md DELETED
@@ -1,13 +0,0 @@
1
- ## 1.0.0-beta.4 (2022-10-23)
2
-
3
- * Refactor with underscore.js
4
- * Optionally set attributes to any nodes not only the first one
5
- * Added more docs
6
-
7
- ## 1.0.0-beta.3 (2022-10-21)
8
-
9
- * Apply additional plugins to tree
10
-
11
- ## 1.0.0-beta.2 (2022-10-20)
12
-
13
- * First beta release