native-document 1.0.168 → 1.0.169

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 (40) hide show
  1. package/CHANGELOG.md +38 -4
  2. package/components.js +3 -1
  3. package/dist/native-document.components.min.js +197 -171
  4. package/dist/native-document.dev.js +92 -75
  5. package/dist/native-document.dev.js.map +1 -1
  6. package/dist/native-document.min.js +1 -1
  7. package/docs/components/icons.md +321 -0
  8. package/package.json +1 -1
  9. package/src/components/form/field/types/FileField.js +3 -3
  10. package/src/components/icon/Icon.js +107 -0
  11. package/src/components/icon/icon-getters.js +142 -0
  12. package/src/components/icon/icons.js +171 -0
  13. package/src/components/icon/index.js +17 -0
  14. package/src/components/icon/types/Icon.d.ts +191 -0
  15. package/src/components/index.d.ts +6 -1
  16. package/src/components/list/types/List.d.ts +45 -32
  17. package/src/components/list/types/ListDivider.ts +16 -0
  18. package/src/components/list/types/ListGroup.d.ts +51 -29
  19. package/src/components/list/types/ListItem.d.ts +20 -21
  20. package/src/core/elements/content-formatter.js +16 -2
  21. package/src/core/elements/form.js +1 -1
  22. package/src/core/elements/img.js +1 -1
  23. package/src/core/elements/medias.js +2 -2
  24. package/src/core/elements/meta-data.js +1 -1
  25. package/src/core/wrappers/AttributesWrapper.js +37 -22
  26. package/src/core/wrappers/ElementCreator.js +9 -16
  27. package/src/core/wrappers/HtmlElementWrapper.js +26 -7
  28. package/src/core/wrappers/NDElement.js +12 -1
  29. package/src/core/wrappers/prototypes/attributes-extensions.js +24 -24
  30. package/src/core/wrappers/prototypes/nd-element-extensions.js +1 -8
  31. package/src/ui/components/icon/material/MaterialIconRender.js +71 -0
  32. package/src/ui/components/icon/material/material.css +15 -0
  33. package/src/ui/components/icon/material/material.map.js +170 -0
  34. package/src/ui/components/icon/phosphor/PhosphorIconRender.js +71 -0
  35. package/src/ui/components/icon/phosphor/phosphor.css +17 -0
  36. package/src/ui/components/icon/phosphor/phosphor.map.js +165 -0
  37. package/src/ui/components/icon/tabler/TablerIconRender.js +59 -0
  38. package/src/ui/components/icon/tabler/tabler.css +14 -0
  39. package/src/ui/components/icon/tabler/tabler.map.js +165 -0
  40. package/src/ui/index.js +5 -0
@@ -3849,27 +3849,31 @@ var NativeDocument = (function (exports) {
3849
3849
  const bindClassAttribute = (element, data) => {
3850
3850
  for(const className in data) {
3851
3851
  const value = data[className];
3852
- if(value.__$Observable) {
3853
- if(value.__$isObservableChecker) {
3854
- let lastClass = value.val();
3855
- if(typeof lastClass === 'string') {
3856
- element.classes.toggle(lastClass, true);
3857
- value.subscribe((currentValue) => {
3858
- element.classes.remove(lastClass);
3859
- element.classes.toggle(currentValue, true);
3860
- lastClass = currentValue;
3861
- });
3862
- continue;
3863
- }
3852
+
3853
+ if (value.__$isObservableChecker) {
3854
+ let lastClass = value.val();
3855
+ if (typeof lastClass === 'string') {
3856
+ element.classes.toggle(lastClass, true);
3857
+ value.subscribe((currentValue) => {
3858
+ element.classes.remove(lastClass);
3859
+ element.classes.toggle(currentValue, true);
3860
+ lastClass = currentValue;
3861
+ });
3862
+ continue;
3864
3863
  }
3864
+ }
3865
+
3866
+ if (value.__$Observable) {
3865
3867
  element.classes.toggle(className, value.val());
3866
3868
  value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
3867
3869
  continue;
3868
3870
  }
3869
- if(value.$hydrate) {
3871
+
3872
+ if (value.$hydrate) {
3870
3873
  value.$hydrate(element, className);
3871
3874
  continue;
3872
3875
  }
3876
+
3873
3877
  element.classes.toggle(className, value);
3874
3878
  }
3875
3879
  };
@@ -3927,12 +3931,12 @@ var NativeDocument = (function (exports) {
3927
3931
  * @param {boolean|number|Observable} value
3928
3932
  */
3929
3933
  const bindBooleanAttribute = (element, attributeName, value) => {
3930
- const isObservable = value.__$isObservable;
3934
+ const isObservable = value.__$Observable;
3931
3935
  const defaultValue = isObservable? value.val() : value;
3932
3936
 
3933
3937
  const attributeRealName = BOOL_ATTRIBUTES_NAME[attributeName];
3934
3938
 
3935
- if(Validator.isBoolean(defaultValue)) {
3939
+ if(typeof defaultValue === 'boolean') {
3936
3940
  element[attributeRealName] = defaultValue;
3937
3941
  }
3938
3942
  else {
@@ -3961,15 +3965,14 @@ var NativeDocument = (function (exports) {
3961
3965
  * @param {Observable} value
3962
3966
  */
3963
3967
  const bindAttributeWithObservable = (element, attributeName, value) => {
3964
- const applyValue = attributeName === 'value' ? (newValue) => element.value = newValue : (newValue) => element.setAttribute(attributeName, newValue);
3965
- value.subscribe(applyValue);
3966
-
3967
3968
  if(attributeName === 'value') {
3968
3969
  element.value = value.val();
3969
3970
  element.addEventListener('input', () => value.set(element.value));
3971
+ value.subscribe((newValue) => element.value = newValue);
3970
3972
  return;
3971
3973
  }
3972
3974
  element.setAttribute(attributeName, value.val());
3975
+ value.subscribe((newValue) => element.setAttribute(attributeName, newValue));
3973
3976
  };
3974
3977
 
3975
3978
  /**
@@ -3984,16 +3987,25 @@ var NativeDocument = (function (exports) {
3984
3987
  }
3985
3988
 
3986
3989
  for(const originalAttributeName in attributes) {
3987
- const attributeName = originalAttributeName.toLowerCase();
3988
3990
  const value = attributes[originalAttributeName];
3989
3991
  if(value == null) {
3990
3992
  continue;
3991
3993
  }
3992
- if(value.handleNdAttribute) {
3993
- value.handleNdAttribute(element, attributeName, value);
3994
+ const type = typeof value;
3995
+ if(type === 'string' || type === 'number') {
3996
+ element.setAttribute(originalAttributeName, value);
3997
+ continue;
3998
+ }
3999
+ const attributeName = originalAttributeName.toLowerCase();
4000
+ if(value.__$Observable) {
4001
+ if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
4002
+ bindBooleanAttribute(element, attributeName, value);
4003
+ continue;
4004
+ }
4005
+ bindAttributeWithObservable(element, originalAttributeName, value);
3994
4006
  continue;
3995
4007
  }
3996
- if(typeof value === 'object') {
4008
+ if(type === 'object') {
3997
4009
  if(attributeName === 'class') {
3998
4010
  bindClassAttribute(element, value);
3999
4011
  continue;
@@ -4007,6 +4019,9 @@ var NativeDocument = (function (exports) {
4007
4019
  bindBooleanAttribute(element, attributeName, value);
4008
4020
  continue;
4009
4021
  }
4022
+ if(value.__$isTemplateBinding) {
4023
+ value.$hydrate(element, attributeName);
4024
+ }
4010
4025
 
4011
4026
  element.setAttribute(attributeName, value);
4012
4027
  }
@@ -4100,30 +4115,23 @@ var NativeDocument = (function (exports) {
4100
4115
 
4101
4116
  },
4102
4117
  getChild: (child) => {
4103
- if(child == null) {
4104
- return null;
4105
- }
4106
- if(child.toNdElement) {
4107
- do {
4108
- child = child.toNdElement();
4109
- if(Validator.isElement(child)) {
4110
- return child;
4111
- }
4112
- } while (child.toNdElement);
4118
+ if (child == null) return null;
4119
+
4120
+ child = child.toNdElement();
4121
+ if (child instanceof Node) return child;
4122
+
4123
+ while (child != null && !(child instanceof Node)) {
4124
+ child = child.toNdElement?.();
4113
4125
  }
4114
4126
 
4115
- return ElementCreator.createStaticTextNode(null, child);
4127
+ return child instanceof Node ? child : null;
4116
4128
  },
4117
4129
  /**
4118
4130
  *
4119
4131
  * @param {HTMLElement} element
4120
4132
  * @param {Object} attributes
4121
4133
  */
4122
- processAttributes: (element, attributes) => {
4123
- if (attributes) {
4124
- AttributesWrapper(element, attributes);
4125
- }
4126
- },
4134
+ processAttributes: AttributesWrapper,
4127
4135
  /**
4128
4136
  *
4129
4137
  * @param {HTMLElement} element
@@ -4800,8 +4808,19 @@ var NativeDocument = (function (exports) {
4800
4808
  NDElement.prototype.ghostDom = function(element) {
4801
4809
  if(!this.$attachements) {
4802
4810
  this.$attachements = document.createDocumentFragment();
4811
+ this.toNdElement = () => {
4812
+ const fragment = document.createDocumentFragment();
4813
+ if(!this.$attachements.contains(this.$element)) {
4814
+ fragment.appendChild(this.$element);
4815
+ }
4816
+ fragment.appendChild(this.$attachements);
4817
+ return fragment;
4818
+ };
4819
+ }
4820
+ const child = NDElement.$getChild(element);
4821
+ if(child) {
4822
+ this.$attachements.appendChild(child);
4803
4823
  }
4804
- this.$attachements.appendChild(NDElement.$getChild(element));
4805
4824
  return this;
4806
4825
  };
4807
4826
 
@@ -5884,14 +5903,7 @@ var NativeDocument = (function (exports) {
5884
5903
  * @returns {HTMLElement|DocumentFragment} The underlying DOM node
5885
5904
  */
5886
5905
  NDElement.prototype.toNdElement = function () {
5887
- const element = this.$element ?? this.$build?.() ?? this.build?.() ?? null;
5888
- if(this.$attachements) {
5889
- if(!this.$attachements.contains(this.$element)) {
5890
- this.$attachements.append(this.$element);
5891
- }
5892
- return this.$attachements;
5893
- }
5894
- return element;
5906
+ return this.$element;
5895
5907
  };
5896
5908
 
5897
5909
  /**
@@ -6059,21 +6071,6 @@ var NativeDocument = (function (exports) {
6059
6071
  return this;
6060
6072
  };
6061
6073
 
6062
- ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
6063
- if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
6064
- bindBooleanAttribute(element, attributeName, this);
6065
- return;
6066
- }
6067
-
6068
- bindAttributeWithObservable(element, attributeName, this);
6069
- };
6070
-
6071
- ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
6072
-
6073
- TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
6074
- this.$hydrate(element, attributeName);
6075
- };
6076
-
6077
6074
  /**
6078
6075
  * Creates a reactive or static text node from the given value.
6079
6076
  * If the value has a .toNdElement() method, delegates to it.
@@ -6090,6 +6087,21 @@ var NativeDocument = (function (exports) {
6090
6087
  };
6091
6088
 
6092
6089
 
6090
+ /**
6091
+ * Applies attributes to an existing HTMLElement.
6092
+ * Used internally by HtmlElementWrapper on each cloned node.
6093
+ *
6094
+ * @internal
6095
+ * @param {HTMLElement} element - Element to configure
6096
+ * @param {Object|null} attributes - Attributes object or children if no attrs provided
6097
+ * @returns {HTMLElement} The configured element
6098
+ */
6099
+ const createVoidHtmlElement = (element, attributes) => {
6100
+ ElementCreator.processAttributes(element, attributes);
6101
+ return element;
6102
+ };
6103
+
6104
+ const OBJECT_PROTOTYPE = Object.prototype;
6093
6105
  /**
6094
6106
  * Applies attributes and children to an existing HTMLElement.
6095
6107
  * Used internally by HtmlElementWrapper on each cloned node.
@@ -6101,7 +6113,11 @@ var NativeDocument = (function (exports) {
6101
6113
  * @returns {HTMLElement} The configured element
6102
6114
  */
6103
6115
  const createHtmlElement = (element, _attributes, _children = null) => {
6104
- const { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
6116
+ let attributes = _attributes, children = _children;
6117
+ if((!_attributes || !_children) && (typeof _attributes !== 'object' || Array.isArray(_attributes) || _attributes === null || Object.getPrototypeOf(_attributes) !== OBJECT_PROTOTYPE || _attributes.$hydrate)) { // IF it's not a JSON
6118
+ attributes = _children;
6119
+ children = _attributes;
6120
+ }
6105
6121
 
6106
6122
  ElementCreator.processAttributes(element, attributes);
6107
6123
  ElementCreator.processChildren(children, element);
@@ -6126,16 +6142,17 @@ var NativeDocument = (function (exports) {
6126
6142
  * return el;
6127
6143
  * });
6128
6144
  */
6129
- function HtmlElementWrapper(name, customWrapper = null) {
6145
+ function HtmlElementWrapper(name, customWrapper = null, isVoid = false) {
6146
+ const elementCreator = isVoid ? createVoidHtmlElement : createHtmlElement;
6130
6147
  if(name) {
6131
6148
  if(customWrapper) {
6132
6149
  let node = null;
6133
6150
  let createElement = (attr, children) => {
6134
6151
  node = document.createElement(name);
6135
6152
  createElement = (attr, children) => {
6136
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children);
6153
+ return elementCreator(customWrapper(node.cloneNode()), attr, children);
6137
6154
  };
6138
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children); };
6155
+ return elementCreator(customWrapper(node.cloneNode()), attr, children); };
6139
6156
 
6140
6157
  return (attr, children) => createElement(attr, children);
6141
6158
  }
@@ -6144,9 +6161,9 @@ var NativeDocument = (function (exports) {
6144
6161
  let createElement = (attr, children) => {
6145
6162
  node = document.createElement(name);
6146
6163
  createElement = (attr, children) => {
6147
- return createHtmlElement(node.cloneNode(), attr, children);
6164
+ return elementCreator(node.cloneNode(), attr, children);
6148
6165
  };
6149
- return createHtmlElement(node.cloneNode(), attr, children);
6166
+ return elementCreator(node.cloneNode(), attr, children);
6150
6167
  };
6151
6168
 
6152
6169
  return (attr, children) => createElement(attr, children);
@@ -8170,7 +8187,7 @@ var NativeDocument = (function (exports) {
8170
8187
  * Creates a `<br>` element.
8171
8188
  * @type {function(GlobalAttributes=): HTMLBRElement}
8172
8189
  */
8173
- const Br = HtmlElementWrapper('br');
8190
+ const Br = HtmlElementWrapper('br', null, true);
8174
8191
 
8175
8192
  /**
8176
8193
  * Creates an `<a>` element.
@@ -8200,7 +8217,7 @@ var NativeDocument = (function (exports) {
8200
8217
  * Creates an `<hr>` element.
8201
8218
  * @type {function(GlobalAttributes=): HTMLHRElement}
8202
8219
  */
8203
- const Hr = HtmlElementWrapper('hr');
8220
+ const Hr = HtmlElementWrapper('hr', null, true);
8204
8221
 
8205
8222
  /**
8206
8223
  * Creates an `<em>` element.
@@ -8323,7 +8340,7 @@ var NativeDocument = (function (exports) {
8323
8340
  * Creates an `<input>` element.
8324
8341
  * @type {function(InputAttributes=): HTMLInputElement}
8325
8342
  */
8326
- const Input = HtmlElementWrapper('input');
8343
+ const Input = HtmlElementWrapper('input', null, true);
8327
8344
 
8328
8345
  /**
8329
8346
  * Creates a `<textarea>` element.
@@ -8591,7 +8608,7 @@ var NativeDocument = (function (exports) {
8591
8608
  * Creates an `<img>` element.
8592
8609
  * @type {function(ImgAttributes=): HTMLImageElement}
8593
8610
  */
8594
- const BaseImage = HtmlElementWrapper('img');
8611
+ const BaseImage = HtmlElementWrapper('img', null, true);
8595
8612
 
8596
8613
  /**
8597
8614
  * Creates an `<img>` element.
@@ -8719,13 +8736,13 @@ var NativeDocument = (function (exports) {
8719
8736
  * Creates a `<source>` element.
8720
8737
  * @type {function(SourceAttributes=): HTMLSourceElement}
8721
8738
  */
8722
- const Source = HtmlElementWrapper('source');
8739
+ const Source = HtmlElementWrapper('source', null, true);
8723
8740
 
8724
8741
  /**
8725
8742
  * Creates a `<track>` element.
8726
8743
  * @type {function(TrackAttributes=): HTMLTrackElement}
8727
8744
  */
8728
- const Track = HtmlElementWrapper('track');
8745
+ const Track = HtmlElementWrapper('track', null, true);
8729
8746
 
8730
8747
  /**
8731
8748
  * Creates a `<canvas>` element.
@@ -8779,7 +8796,7 @@ var NativeDocument = (function (exports) {
8779
8796
  * Creates a `<wbr>` element.
8780
8797
  * @type {function(GlobalAttributes=): HTMLElement}
8781
8798
  */
8782
- const Wbr = HtmlElementWrapper('wbr');
8799
+ const Wbr = HtmlElementWrapper('wbr', null, true);
8783
8800
 
8784
8801
  /**
8785
8802
  * Creates a `<caption>` element.