native-document 1.0.16-8.4 → 1.0.16-8.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": "native-document",
3
- "version": "1.0.168.04",
3
+ "version": "1.0.168.05",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -76,7 +76,7 @@ export const H6 = HtmlElementWrapper('h6');
76
76
  * Creates a `<br>` element.
77
77
  * @type {function(GlobalAttributes=): HTMLBRElement}
78
78
  */
79
- export const Br = HtmlElementWrapper('br');
79
+ export const Br = HtmlElementWrapper('br', null, true);
80
80
 
81
81
  /**
82
82
  * Creates an `<a>` element.
@@ -106,7 +106,7 @@ export const Blockquote = HtmlElementWrapper('blockquote');
106
106
  * Creates an `<hr>` element.
107
107
  * @type {function(GlobalAttributes=): HTMLHRElement}
108
108
  */
109
- export const Hr = HtmlElementWrapper('hr');
109
+ export const Hr = HtmlElementWrapper('hr', null, true);
110
110
 
111
111
  /**
112
112
  * Creates an `<em>` element.
@@ -44,7 +44,7 @@ export const Form = HtmlElementWrapper('form', (el) => {
44
44
  * Creates an `<input>` element.
45
45
  * @type {function(InputAttributes=): HTMLInputElement}
46
46
  */
47
- export const Input = HtmlElementWrapper('input');
47
+ export const Input = HtmlElementWrapper('input', null, true);
48
48
 
49
49
  /**
50
50
  * Creates a `<textarea>` element.
@@ -6,7 +6,7 @@ import NativeDocumentError from '../errors/NativeDocumentError';
6
6
  * Creates an `<img>` element.
7
7
  * @type {function(ImgAttributes=): HTMLImageElement}
8
8
  */
9
- export const BaseImage = HtmlElementWrapper('img');
9
+ export const BaseImage = HtmlElementWrapper('img', null, true);
10
10
 
11
11
  /**
12
12
  * Creates an `<img>` element.
@@ -16,13 +16,13 @@ export const Video = HtmlElementWrapper('video');
16
16
  * Creates a `<source>` element.
17
17
  * @type {function(SourceAttributes=): HTMLSourceElement}
18
18
  */
19
- export const Source = HtmlElementWrapper('source');
19
+ export const Source = HtmlElementWrapper('source', null, true);
20
20
 
21
21
  /**
22
22
  * Creates a `<track>` element.
23
23
  * @type {function(TrackAttributes=): HTMLTrackElement}
24
24
  */
25
- export const Track = HtmlElementWrapper('track');
25
+ export const Track = HtmlElementWrapper('track', null, true);
26
26
 
27
27
  /**
28
28
  * Creates a `<canvas>` element.
@@ -40,4 +40,4 @@ export const Var = HtmlElementWrapper('var');
40
40
  * Creates a `<wbr>` element.
41
41
  * @type {function(GlobalAttributes=): HTMLElement}
42
42
  */
43
- export const Wbr = HtmlElementWrapper('wbr');
43
+ export const Wbr = HtmlElementWrapper('wbr', null, true);
@@ -154,8 +154,12 @@ const AttributesWrapper = (element, attributes) => {
154
154
  if(value == null) {
155
155
  continue;
156
156
  }
157
- if(value.handleNdAttribute) {
158
- value.handleNdAttribute(element, attributeName, value);
157
+ if(typeof value === 'string' || typeof value === 'number') {
158
+ element.setAttribute(attributeName, value);
159
+ continue;
160
+ }
161
+ if(value.__$Observable) {
162
+ bindAttributeWithObservable(element, attributeName, value);
159
163
  continue;
160
164
  }
161
165
  if(typeof value === 'object') {
@@ -172,6 +176,9 @@ const AttributesWrapper = (element, attributes) => {
172
176
  bindBooleanAttribute(element, attributeName, value);
173
177
  continue;
174
178
  }
179
+ if(value.__$isTemplateBinding) {
180
+ value.$hydrate(element, attributeName);
181
+ }
175
182
 
176
183
  element.setAttribute(attributeName, value);
177
184
  }
@@ -104,11 +104,7 @@ export const ElementCreator = {
104
104
  * @param {HTMLElement} element
105
105
  * @param {Object} attributes
106
106
  */
107
- processAttributes: (element, attributes) => {
108
- if (attributes) {
109
- AttributesWrapper(element, attributes);
110
- }
111
- },
107
+ processAttributes: AttributesWrapper,
112
108
  /**
113
109
  *
114
110
  * @param {HTMLElement} element
@@ -3,7 +3,6 @@ import {ElementCreator} from './ElementCreator';
3
3
  import {normalizeComponentArgs} from '../utils/args-types';
4
4
  import './NdPrototype';
5
5
 
6
- import './NdPrototype';
7
6
  import '../../core/utils/prototypes.js';
8
7
  import '../wrappers/prototypes/nd-element-extensions';
9
8
  import '../wrappers/prototypes/bind-class-extensions';
@@ -27,6 +26,19 @@ export const createTextNode = (value) => {
27
26
  };
28
27
 
29
28
 
29
+ /**
30
+ * Applies attributes to an existing HTMLElement.
31
+ * Used internally by HtmlElementWrapper on each cloned node.
32
+ *
33
+ * @internal
34
+ * @param {HTMLElement} element - Element to configure
35
+ * @param {Object|null} attributes - Attributes object or children if no attrs provided
36
+ * @returns {HTMLElement} The configured element
37
+ */
38
+ export const createVoidHtmlElement = (element, attributes) => {
39
+ ElementCreator.processAttributes(element, attributes);
40
+ return element;
41
+ };
30
42
  /**
31
43
  * Applies attributes and children to an existing HTMLElement.
32
44
  * Used internally by HtmlElementWrapper on each cloned node.
@@ -38,7 +50,11 @@ export const createTextNode = (value) => {
38
50
  * @returns {HTMLElement} The configured element
39
51
  */
40
52
  export const createHtmlElement = (element, _attributes, _children = null) => {
41
- const { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
53
+ let attributes = _attributes, children = _children;
54
+ if((!_attributes || !_children) && (typeof _attributes !== 'object' || Array.isArray(_attributes) || _attributes === null || Object.getPrototypeOf(_attributes) !== Object.prototype || _attributes.$hydrate)) { // IF it's not a JSON
55
+ attributes = _children;
56
+ children = _attributes;
57
+ }
42
58
 
43
59
  ElementCreator.processAttributes(element, attributes);
44
60
  ElementCreator.processChildren(children, element);
@@ -63,16 +79,17 @@ export const createHtmlElement = (element, _attributes, _children = null) => {
63
79
  * return el;
64
80
  * });
65
81
  */
66
- export default function HtmlElementWrapper(name, customWrapper = null) {
82
+ export default function HtmlElementWrapper(name, customWrapper = null, isVoid = false) {
83
+ const elementCreator = isVoid ? createVoidHtmlElement : createHtmlElement;
67
84
  if(name) {
68
85
  if(customWrapper) {
69
86
  let node = null;
70
87
  let createElement = (attr, children) => {
71
88
  node = document.createElement(name);
72
89
  createElement = (attr, children) => {
73
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children);
90
+ return elementCreator(customWrapper(node.cloneNode()), attr, children);
74
91
  };
75
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children);;
92
+ return elementCreator(customWrapper(node.cloneNode()), attr, children);;
76
93
  };
77
94
 
78
95
  return (attr, children) => createElement(attr, children);
@@ -82,9 +99,9 @@ export default function HtmlElementWrapper(name, customWrapper = null) {
82
99
  let createElement = (attr, children) => {
83
100
  node = document.createElement(name);
84
101
  createElement = (attr, children) => {
85
- return createHtmlElement(node.cloneNode(), attr, children);
102
+ return elementCreator(node.cloneNode(), attr, children);
86
103
  };
87
- return createHtmlElement(node.cloneNode(), attr, children);
104
+ return elementCreator(node.cloneNode(), attr, children);
88
105
  };
89
106
 
90
107
  return (attr, children) => createElement(attr, children);
@@ -1,24 +1,24 @@
1
- import {
2
- bindAttributeWithObservable,
3
- bindBooleanAttribute,
4
- } from '../AttributesWrapper';
5
- import ObservableItem from '../../data/ObservableItem';
6
- import TemplateBinding from '../TemplateBinding';
7
- import {BOOLEAN_ATTRIBUTES} from '../constants';
8
- import ObservableChecker from '../../data/ObservableChecker';
9
-
10
-
11
- ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
12
- if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
13
- bindBooleanAttribute(element, attributeName, this);
14
- return;
15
- }
16
-
17
- bindAttributeWithObservable(element, attributeName, this);
18
- };
19
-
20
- ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
21
-
22
- TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
23
- this.$hydrate(element, attributeName);
24
- };
1
+ // import {
2
+ // bindAttributeWithObservable,
3
+ // bindBooleanAttribute,
4
+ // } from '../AttributesWrapper';
5
+ // import ObservableItem from '../../data/ObservableItem';
6
+ // import TemplateBinding from '../TemplateBinding';
7
+ // import {BOOLEAN_ATTRIBUTES} from '../constants';
8
+ // import ObservableChecker from '../../data/ObservableChecker';
9
+ //
10
+ //
11
+ // ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
12
+ // if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
13
+ // bindBooleanAttribute(element, attributeName, this);
14
+ // return;
15
+ // }
16
+ //
17
+ // bindAttributeWithObservable(element, attributeName, this);
18
+ // };
19
+ //
20
+ // ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
21
+ //
22
+ // TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
23
+ // this.$hydrate(element, attributeName);
24
+ // };