native-document 1.0.166 → 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 (139) hide show
  1. package/.vitepress/config.js +166 -0
  2. package/CHANGELOG.md +187 -0
  3. package/components.js +4 -1
  4. package/dist/native-document.components.min.js +593 -300
  5. package/dist/native-document.dev.js +99 -75
  6. package/dist/native-document.dev.js.map +1 -1
  7. package/dist/native-document.min.js +1 -1
  8. package/docs/advanced-components.md +213 -608
  9. package/docs/anchor.md +173 -312
  10. package/docs/cache.md +95 -803
  11. package/docs/cli.md +179 -0
  12. package/docs/components/accordion.md +172 -0
  13. package/docs/components/alert.md +99 -0
  14. package/docs/components/avatar.md +160 -0
  15. package/docs/components/badge.md +102 -0
  16. package/docs/components/breadcrumb.md +89 -0
  17. package/docs/components/button.md +183 -0
  18. package/docs/components/card.md +69 -0
  19. package/docs/components/context-menu.md +118 -0
  20. package/docs/components/data-table.md +345 -0
  21. package/docs/components/dropdown.md +214 -0
  22. package/docs/components/form/autocomplete-field.md +81 -0
  23. package/docs/components/form/checkbox-field.md +41 -0
  24. package/docs/components/form/checkbox-group-field.md +54 -0
  25. package/docs/components/form/color-field.md +64 -0
  26. package/docs/components/form/date-field.md +92 -0
  27. package/docs/components/form/field-collection.md +63 -0
  28. package/docs/components/form/file-field.md +203 -0
  29. package/docs/components/form/form-control.md +87 -0
  30. package/docs/components/form/image-field.md +90 -0
  31. package/docs/components/form/index.md +115 -0
  32. package/docs/components/form/number-field.md +65 -0
  33. package/docs/components/form/radio-field.md +51 -0
  34. package/docs/components/form/select-field.md +123 -0
  35. package/docs/components/form/slider.md +136 -0
  36. package/docs/components/form/string-field.md +134 -0
  37. package/docs/components/form/textarea-field.md +65 -0
  38. package/docs/components/form-fields.md +372 -0
  39. package/docs/components/getting-started.md +264 -0
  40. package/docs/components/icons.md +321 -0
  41. package/docs/components/index.md +337 -0
  42. package/docs/components/layout.md +279 -0
  43. package/docs/components/list.md +73 -0
  44. package/docs/components/menu.md +215 -0
  45. package/docs/components/modal.md +156 -0
  46. package/docs/components/pagination.md +95 -0
  47. package/docs/components/popover.md +131 -0
  48. package/docs/components/progress.md +111 -0
  49. package/docs/components/shortcut-manager.md +221 -0
  50. package/docs/components/simple-table.md +107 -0
  51. package/docs/components/skeleton.md +155 -0
  52. package/docs/components/spinner.md +100 -0
  53. package/docs/components/splitter.md +133 -0
  54. package/docs/components/stepper.md +163 -0
  55. package/docs/components/switch.md +113 -0
  56. package/docs/components/tabs.md +153 -0
  57. package/docs/components/toast.md +119 -0
  58. package/docs/components/tooltip.md +151 -0
  59. package/docs/components/traits.md +261 -0
  60. package/docs/conditional-rendering.md +170 -588
  61. package/docs/contributing.md +300 -25
  62. package/docs/core-concepts.md +205 -374
  63. package/docs/elements.md +251 -367
  64. package/docs/extending-native-document-element.md +192 -207
  65. package/docs/filters.md +153 -1122
  66. package/docs/getting-started.md +193 -267
  67. package/docs/i18n.md +241 -0
  68. package/docs/index.md +76 -0
  69. package/docs/lifecycle-events.md +143 -75
  70. package/docs/list-rendering.md +227 -852
  71. package/docs/memory-management.md +134 -47
  72. package/docs/native-document-element.md +337 -186
  73. package/docs/native-fetch.md +99 -630
  74. package/docs/observable-resource.md +364 -0
  75. package/docs/observables.md +592 -526
  76. package/docs/routing.md +244 -653
  77. package/docs/state-management.md +134 -241
  78. package/docs/svg-elements.md +231 -0
  79. package/docs/theming.md +409 -0
  80. package/docs/tutorials/.gitkeep +0 -0
  81. package/docs/validation.md +95 -97
  82. package/docs/vitepress-conventions.md +219 -0
  83. package/package.json +34 -13
  84. package/readme.md +269 -89
  85. package/src/components/card/Card.js +93 -39
  86. package/src/components/card/index.js +1 -1
  87. package/src/components/form/field/types/FileField.js +3 -3
  88. package/src/components/icon/Icon.js +107 -0
  89. package/src/components/icon/icon-getters.js +142 -0
  90. package/src/components/icon/icons.js +171 -0
  91. package/src/components/icon/index.js +17 -0
  92. package/src/components/icon/types/Icon.d.ts +191 -0
  93. package/src/components/index.d.ts +6 -1
  94. package/src/components/list/HasListItem.js +171 -0
  95. package/src/components/list/List.js +41 -107
  96. package/src/components/list/ListDivider.js +39 -0
  97. package/src/components/list/ListGroup.js +76 -59
  98. package/src/components/list/ListItem.js +117 -69
  99. package/src/components/list/index.js +3 -1
  100. package/src/components/list/types/List.d.ts +45 -32
  101. package/src/components/list/types/ListDivider.ts +16 -0
  102. package/src/components/list/types/ListGroup.d.ts +51 -29
  103. package/src/components/list/types/ListItem.d.ts +40 -30
  104. package/src/components/spacer/Spacer.js +1 -1
  105. package/src/core/data/ObservableResource.js +5 -0
  106. package/src/core/data/observable-helpers/observable.prototypes.js +2 -0
  107. package/src/core/elements/content-formatter.js +16 -2
  108. package/src/core/elements/form.js +1 -1
  109. package/src/core/elements/img.js +1 -1
  110. package/src/core/elements/medias.js +2 -2
  111. package/src/core/elements/meta-data.js +1 -1
  112. package/src/core/wrappers/AttributesWrapper.js +37 -22
  113. package/src/core/wrappers/ElementCreator.js +9 -16
  114. package/src/core/wrappers/HtmlElementWrapper.js +26 -7
  115. package/src/core/wrappers/NDElement.js +12 -1
  116. package/src/core/wrappers/prototypes/attributes-extensions.js +24 -24
  117. package/src/core/wrappers/prototypes/nd-element-extensions.js +1 -8
  118. package/src/ui/components/card/CardRender.js +133 -0
  119. package/src/ui/components/card/card.css +169 -0
  120. package/src/ui/components/contextmenu/ContextmenuRender.js +1 -1
  121. package/src/ui/components/icon/material/MaterialIconRender.js +71 -0
  122. package/src/ui/components/icon/material/material.css +15 -0
  123. package/src/ui/components/icon/material/material.map.js +170 -0
  124. package/src/ui/components/icon/phosphor/PhosphorIconRender.js +71 -0
  125. package/src/ui/components/icon/phosphor/phosphor.css +17 -0
  126. package/src/ui/components/icon/phosphor/phosphor.map.js +165 -0
  127. package/src/ui/components/icon/tabler/TablerIconRender.js +59 -0
  128. package/src/ui/components/icon/tabler/tabler.css +14 -0
  129. package/src/ui/components/icon/tabler/tabler.map.js +165 -0
  130. package/src/ui/components/list/ListRender.js +18 -0
  131. package/src/ui/components/list/divider/ListDividerRender.js +10 -0
  132. package/src/ui/components/list/divider/list-divider.css +12 -0
  133. package/src/ui/components/list/group/ListGroupRender.js +61 -0
  134. package/src/ui/components/list/group/list-group.css +62 -0
  135. package/src/ui/components/list/item/ListItemRender.js +238 -0
  136. package/src/ui/components/list/item/list-item.css +191 -0
  137. package/src/ui/components/list/list.css +24 -0
  138. package/src/ui/components/spacer/SpacerRender.js +10 -0
  139. package/src/ui/index.js +13 -0
@@ -3285,6 +3285,8 @@ var NativeDocument = (function (exports) {
3285
3285
  * // Reacts to locale changes automatically
3286
3286
  * Store.setLocale('en-US');
3287
3287
  */
3288
+
3289
+
3288
3290
  ObservableItem.prototype.format = function(type, options = {}) {
3289
3291
  const self = this;
3290
3292
 
@@ -3433,6 +3435,11 @@ var NativeDocument = (function (exports) {
3433
3435
  });
3434
3436
  };
3435
3437
 
3438
+ ObservableResource.prototype.into = function($observable) {
3439
+ this.data = $observable;
3440
+ return this;
3441
+ };
3442
+
3436
3443
  ObservableResource.prototype.$run = function(isRefetch = false) {
3437
3444
  const needsSignal = this.$fn.length > this.$dependencies.length;
3438
3445
  if(needsSignal) {
@@ -3842,27 +3849,31 @@ var NativeDocument = (function (exports) {
3842
3849
  const bindClassAttribute = (element, data) => {
3843
3850
  for(const className in data) {
3844
3851
  const value = data[className];
3845
- if(value.__$Observable) {
3846
- if(value.__$isObservableChecker) {
3847
- let lastClass = value.val();
3848
- if(typeof lastClass === 'string') {
3849
- element.classes.toggle(lastClass, true);
3850
- value.subscribe((currentValue) => {
3851
- element.classes.remove(lastClass);
3852
- element.classes.toggle(currentValue, true);
3853
- lastClass = currentValue;
3854
- });
3855
- continue;
3856
- }
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;
3857
3863
  }
3864
+ }
3865
+
3866
+ if (value.__$Observable) {
3858
3867
  element.classes.toggle(className, value.val());
3859
3868
  value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
3860
3869
  continue;
3861
3870
  }
3862
- if(value.$hydrate) {
3871
+
3872
+ if (value.$hydrate) {
3863
3873
  value.$hydrate(element, className);
3864
3874
  continue;
3865
3875
  }
3876
+
3866
3877
  element.classes.toggle(className, value);
3867
3878
  }
3868
3879
  };
@@ -3920,12 +3931,12 @@ var NativeDocument = (function (exports) {
3920
3931
  * @param {boolean|number|Observable} value
3921
3932
  */
3922
3933
  const bindBooleanAttribute = (element, attributeName, value) => {
3923
- const isObservable = value.__$isObservable;
3934
+ const isObservable = value.__$Observable;
3924
3935
  const defaultValue = isObservable? value.val() : value;
3925
3936
 
3926
3937
  const attributeRealName = BOOL_ATTRIBUTES_NAME[attributeName];
3927
3938
 
3928
- if(Validator.isBoolean(defaultValue)) {
3939
+ if(typeof defaultValue === 'boolean') {
3929
3940
  element[attributeRealName] = defaultValue;
3930
3941
  }
3931
3942
  else {
@@ -3954,15 +3965,14 @@ var NativeDocument = (function (exports) {
3954
3965
  * @param {Observable} value
3955
3966
  */
3956
3967
  const bindAttributeWithObservable = (element, attributeName, value) => {
3957
- const applyValue = attributeName === 'value' ? (newValue) => element.value = newValue : (newValue) => element.setAttribute(attributeName, newValue);
3958
- value.subscribe(applyValue);
3959
-
3960
3968
  if(attributeName === 'value') {
3961
3969
  element.value = value.val();
3962
3970
  element.addEventListener('input', () => value.set(element.value));
3971
+ value.subscribe((newValue) => element.value = newValue);
3963
3972
  return;
3964
3973
  }
3965
3974
  element.setAttribute(attributeName, value.val());
3975
+ value.subscribe((newValue) => element.setAttribute(attributeName, newValue));
3966
3976
  };
3967
3977
 
3968
3978
  /**
@@ -3977,16 +3987,25 @@ var NativeDocument = (function (exports) {
3977
3987
  }
3978
3988
 
3979
3989
  for(const originalAttributeName in attributes) {
3980
- const attributeName = originalAttributeName.toLowerCase();
3981
3990
  const value = attributes[originalAttributeName];
3982
3991
  if(value == null) {
3983
3992
  continue;
3984
3993
  }
3985
- if(value.handleNdAttribute) {
3986
- 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);
3987
4006
  continue;
3988
4007
  }
3989
- if(typeof value === 'object') {
4008
+ if(type === 'object') {
3990
4009
  if(attributeName === 'class') {
3991
4010
  bindClassAttribute(element, value);
3992
4011
  continue;
@@ -4000,6 +4019,9 @@ var NativeDocument = (function (exports) {
4000
4019
  bindBooleanAttribute(element, attributeName, value);
4001
4020
  continue;
4002
4021
  }
4022
+ if(value.__$isTemplateBinding) {
4023
+ value.$hydrate(element, attributeName);
4024
+ }
4003
4025
 
4004
4026
  element.setAttribute(attributeName, value);
4005
4027
  }
@@ -4093,30 +4115,23 @@ var NativeDocument = (function (exports) {
4093
4115
 
4094
4116
  },
4095
4117
  getChild: (child) => {
4096
- if(child == null) {
4097
- return null;
4098
- }
4099
- if(child.toNdElement) {
4100
- do {
4101
- child = child.toNdElement();
4102
- if(Validator.isElement(child)) {
4103
- return child;
4104
- }
4105
- } 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?.();
4106
4125
  }
4107
4126
 
4108
- return ElementCreator.createStaticTextNode(null, child);
4127
+ return child instanceof Node ? child : null;
4109
4128
  },
4110
4129
  /**
4111
4130
  *
4112
4131
  * @param {HTMLElement} element
4113
4132
  * @param {Object} attributes
4114
4133
  */
4115
- processAttributes: (element, attributes) => {
4116
- if (attributes) {
4117
- AttributesWrapper(element, attributes);
4118
- }
4119
- },
4134
+ processAttributes: AttributesWrapper,
4120
4135
  /**
4121
4136
  *
4122
4137
  * @param {HTMLElement} element
@@ -4793,8 +4808,19 @@ var NativeDocument = (function (exports) {
4793
4808
  NDElement.prototype.ghostDom = function(element) {
4794
4809
  if(!this.$attachements) {
4795
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);
4796
4823
  }
4797
- this.$attachements.appendChild(NDElement.$getChild(element));
4798
4824
  return this;
4799
4825
  };
4800
4826
 
@@ -5877,14 +5903,7 @@ var NativeDocument = (function (exports) {
5877
5903
  * @returns {HTMLElement|DocumentFragment} The underlying DOM node
5878
5904
  */
5879
5905
  NDElement.prototype.toNdElement = function () {
5880
- const element = this.$element ?? this.$build?.() ?? this.build?.() ?? null;
5881
- if(this.$attachements) {
5882
- if(!this.$attachements.contains(this.$element)) {
5883
- this.$attachements.append(this.$element);
5884
- }
5885
- return this.$attachements;
5886
- }
5887
- return element;
5906
+ return this.$element;
5888
5907
  };
5889
5908
 
5890
5909
  /**
@@ -6052,21 +6071,6 @@ var NativeDocument = (function (exports) {
6052
6071
  return this;
6053
6072
  };
6054
6073
 
6055
- ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
6056
- if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
6057
- bindBooleanAttribute(element, attributeName, this);
6058
- return;
6059
- }
6060
-
6061
- bindAttributeWithObservable(element, attributeName, this);
6062
- };
6063
-
6064
- ObservableChecker.prototype.handleNdAttribute = ObservableItem.prototype.handleNdAttribute;
6065
-
6066
- TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
6067
- this.$hydrate(element, attributeName);
6068
- };
6069
-
6070
6074
  /**
6071
6075
  * Creates a reactive or static text node from the given value.
6072
6076
  * If the value has a .toNdElement() method, delegates to it.
@@ -6083,6 +6087,21 @@ var NativeDocument = (function (exports) {
6083
6087
  };
6084
6088
 
6085
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;
6086
6105
  /**
6087
6106
  * Applies attributes and children to an existing HTMLElement.
6088
6107
  * Used internally by HtmlElementWrapper on each cloned node.
@@ -6094,7 +6113,11 @@ var NativeDocument = (function (exports) {
6094
6113
  * @returns {HTMLElement} The configured element
6095
6114
  */
6096
6115
  const createHtmlElement = (element, _attributes, _children = null) => {
6097
- 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
+ }
6098
6121
 
6099
6122
  ElementCreator.processAttributes(element, attributes);
6100
6123
  ElementCreator.processChildren(children, element);
@@ -6119,16 +6142,17 @@ var NativeDocument = (function (exports) {
6119
6142
  * return el;
6120
6143
  * });
6121
6144
  */
6122
- function HtmlElementWrapper(name, customWrapper = null) {
6145
+ function HtmlElementWrapper(name, customWrapper = null, isVoid = false) {
6146
+ const elementCreator = isVoid ? createVoidHtmlElement : createHtmlElement;
6123
6147
  if(name) {
6124
6148
  if(customWrapper) {
6125
6149
  let node = null;
6126
6150
  let createElement = (attr, children) => {
6127
6151
  node = document.createElement(name);
6128
6152
  createElement = (attr, children) => {
6129
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children);
6153
+ return elementCreator(customWrapper(node.cloneNode()), attr, children);
6130
6154
  };
6131
- return createHtmlElement(customWrapper(node.cloneNode()), attr, children); };
6155
+ return elementCreator(customWrapper(node.cloneNode()), attr, children); };
6132
6156
 
6133
6157
  return (attr, children) => createElement(attr, children);
6134
6158
  }
@@ -6137,9 +6161,9 @@ var NativeDocument = (function (exports) {
6137
6161
  let createElement = (attr, children) => {
6138
6162
  node = document.createElement(name);
6139
6163
  createElement = (attr, children) => {
6140
- return createHtmlElement(node.cloneNode(), attr, children);
6164
+ return elementCreator(node.cloneNode(), attr, children);
6141
6165
  };
6142
- return createHtmlElement(node.cloneNode(), attr, children);
6166
+ return elementCreator(node.cloneNode(), attr, children);
6143
6167
  };
6144
6168
 
6145
6169
  return (attr, children) => createElement(attr, children);
@@ -8163,7 +8187,7 @@ var NativeDocument = (function (exports) {
8163
8187
  * Creates a `<br>` element.
8164
8188
  * @type {function(GlobalAttributes=): HTMLBRElement}
8165
8189
  */
8166
- const Br = HtmlElementWrapper('br');
8190
+ const Br = HtmlElementWrapper('br', null, true);
8167
8191
 
8168
8192
  /**
8169
8193
  * Creates an `<a>` element.
@@ -8193,7 +8217,7 @@ var NativeDocument = (function (exports) {
8193
8217
  * Creates an `<hr>` element.
8194
8218
  * @type {function(GlobalAttributes=): HTMLHRElement}
8195
8219
  */
8196
- const Hr = HtmlElementWrapper('hr');
8220
+ const Hr = HtmlElementWrapper('hr', null, true);
8197
8221
 
8198
8222
  /**
8199
8223
  * Creates an `<em>` element.
@@ -8316,7 +8340,7 @@ var NativeDocument = (function (exports) {
8316
8340
  * Creates an `<input>` element.
8317
8341
  * @type {function(InputAttributes=): HTMLInputElement}
8318
8342
  */
8319
- const Input = HtmlElementWrapper('input');
8343
+ const Input = HtmlElementWrapper('input', null, true);
8320
8344
 
8321
8345
  /**
8322
8346
  * Creates a `<textarea>` element.
@@ -8584,7 +8608,7 @@ var NativeDocument = (function (exports) {
8584
8608
  * Creates an `<img>` element.
8585
8609
  * @type {function(ImgAttributes=): HTMLImageElement}
8586
8610
  */
8587
- const BaseImage = HtmlElementWrapper('img');
8611
+ const BaseImage = HtmlElementWrapper('img', null, true);
8588
8612
 
8589
8613
  /**
8590
8614
  * Creates an `<img>` element.
@@ -8712,13 +8736,13 @@ var NativeDocument = (function (exports) {
8712
8736
  * Creates a `<source>` element.
8713
8737
  * @type {function(SourceAttributes=): HTMLSourceElement}
8714
8738
  */
8715
- const Source = HtmlElementWrapper('source');
8739
+ const Source = HtmlElementWrapper('source', null, true);
8716
8740
 
8717
8741
  /**
8718
8742
  * Creates a `<track>` element.
8719
8743
  * @type {function(TrackAttributes=): HTMLTrackElement}
8720
8744
  */
8721
- const Track = HtmlElementWrapper('track');
8745
+ const Track = HtmlElementWrapper('track', null, true);
8722
8746
 
8723
8747
  /**
8724
8748
  * Creates a `<canvas>` element.
@@ -8772,7 +8796,7 @@ var NativeDocument = (function (exports) {
8772
8796
  * Creates a `<wbr>` element.
8773
8797
  * @type {function(GlobalAttributes=): HTMLElement}
8774
8798
  */
8775
- const Wbr = HtmlElementWrapper('wbr');
8799
+ const Wbr = HtmlElementWrapper('wbr', null, true);
8776
8800
 
8777
8801
  /**
8778
8802
  * Creates a `<caption>` element.