rasti 4.0.0-alpha.8 → 4.0.0-alpha.9

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <p align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.0.0-alpha.8/docs/logo-dark.svg">
4
- <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.0.0-alpha.8/docs/logo.svg" height="120">
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.0.0-alpha.9/docs/logo-dark.svg">
4
+ <img alt="Rasti.js" src="https://cdn.jsdelivr.net/gh/8tentaculos/rasti@v4.0.0-alpha.9/docs/logo.svg" height="120">
5
5
  </picture>
6
6
  </p>
7
7
 
package/dist/rasti.js CHANGED
@@ -845,7 +845,7 @@
845
845
  * Destroy the view.
846
846
  * Destroy children views if any, undelegate events, stop listening to events, call `onDestroy` lifecycle method.
847
847
  * @param {object} options Options object or any arguments passed to `destroy` method will be passed to `onDestroy` method.
848
- * @return {Rasti.View} Return `this` for chaining.
848
+ * @return {View} Return `this` for chaining.
849
849
  */
850
850
  destroy() {
851
851
  // Call destroy on children.
@@ -878,8 +878,8 @@
878
878
  * Add a view as a child.
879
879
  * Children views are stored at `this.children`, and destroyed when the parent is destroyed.
880
880
  * Returns the child for chaining.
881
- * @param {Rasti.View} child
882
- * @return {Rasti.View}
881
+ * @param {View} child
882
+ * @return {View}
883
883
  */
884
884
  addChild(child) {
885
885
  this.children.push(child);
@@ -944,7 +944,7 @@
944
944
 
945
945
  /**
946
946
  * Remove `this.el` from the DOM.
947
- * @return {Rasti.View} Return `this` for chaining.
947
+ * @return {View} Return `this` for chaining.
948
948
  */
949
949
  removeElement() {
950
950
  this.el.parentNode.removeChild(this.el);
@@ -976,7 +976,7 @@
976
976
  * invoked **once for each matched element** (from inner to outer).
977
977
  *
978
978
  * @param {object} [events] Object in the format `{'event selector' : 'listener'}`. Used to bind delegated event listeners to the root element.
979
- * @return {Rasti.View} Returns `this` for chaining.
979
+ * @return {View} Returns `this` for chaining.
980
980
  * @example
981
981
  * // Using prototype (recommended for static events)
982
982
  * class Modal extends View {
@@ -1063,7 +1063,7 @@
1063
1063
  * Removes all of the view's delegated events.
1064
1064
  * Useful if you want to disable or remove a view from the DOM temporarily.
1065
1065
  * Called automatically when the view is destroyed and when `delegateEvents` is called again.
1066
- * @return {Rasti.View} Return `this` for chaining.
1066
+ * @return {View} Return `this` for chaining.
1067
1067
  */
1068
1068
  undelegateEvents() {
1069
1069
  this.delegatedEventListeners.forEach(({ type, listener }) => {
@@ -1088,7 +1088,7 @@
1088
1088
  * You can use the {@link #module_view_sanitize View.sanitize} static method to escape HTML entities in a string.
1089
1089
  * For best practices on secure data handling, refer to the
1090
1090
  * [OWASP's XSS Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html).<br><br>
1091
- * @return {Rasti.View} Returns `this` for chaining.
1091
+ * @return {View} Returns `this` for chaining.
1092
1092
  */
1093
1093
  render() {
1094
1094
  if (this.template) this.el.innerHTML = this.template(this.model);
@@ -1114,6 +1114,17 @@
1114
1114
  '\'' : '&#039;'
1115
1115
  }[match]));
1116
1116
  }
1117
+
1118
+ /**
1119
+ * Reset the unique ID counter to 0.
1120
+ * This is useful for server-side rendering scenarios where you want to ensure that
1121
+ * the generated unique IDs match those on the client, enabling seamless hydration of components.
1122
+ * This method is inherited by {@link #module_component Component}.
1123
+ * @static
1124
+ */
1125
+ static resetUid() {
1126
+ View.uid = 0;
1127
+ }
1117
1128
  }
1118
1129
 
1119
1130
  /**
@@ -2779,7 +2790,7 @@
2779
2790
  * This method can be extended with custom logic.
2780
2791
  * Maybe comparing new attributes with previous ones and calling
2781
2792
  * render when needed.
2782
- * @param model {Rasti.Model} The model that emitted the event.
2793
+ * @param model {Model} The model that emitted the event.
2783
2794
  * @param changed {object} Object containing keys and values that has changed.
2784
2795
  * @param [...args] {any} Any extra arguments passed to set method.
2785
2796
  */
@@ -3091,25 +3102,25 @@
3091
3102
  /*
3092
3103
  * Attributes used to identify elements and events.
3093
3104
  */
3094
- Component.ATTRIBUTE_ELEMENT = 'data-rasti-el';
3095
- Component.ATTRIBUTE_EVENT = (type, uid) => `data-rasti-on-${type}-${uid}`;
3105
+ Component.ATTRIBUTE_ELEMENT = 'data-rst-el';
3106
+ Component.ATTRIBUTE_EVENT = (type, uid) => `data-rst-on-${type}-${uid}`;
3096
3107
 
3097
3108
  /*
3098
3109
  * Dataset attribute used to identify elements.
3099
3110
  */
3100
- Component.DATASET_ELEMENT = 'rastiEl';
3111
+ Component.DATASET_ELEMENT = 'rstEl';
3101
3112
 
3102
3113
  /*
3103
3114
  * Placeholders used to temporarily replace expressions in the template.
3104
3115
  */
3105
- Component.PLACEHOLDER = (idx) => `__RASTI_PH_${idx}__`;
3116
+ Component.PLACEHOLDER = (idx) => `__RASTI_PLACEHOLDER_${idx}__`;
3106
3117
 
3107
3118
  /*
3108
3119
  * Markers used to identify interpolation and recycled components.
3109
3120
  */
3110
- Component.MARKER_RECYCLED = (uid) => `rasti-r-${uid}`;
3111
- Component.MARKER_START = (uid) => `rasti-s-${uid}`;
3112
- Component.MARKER_END = (uid) => `rasti-e-${uid}`;
3121
+ Component.MARKER_RECYCLED = (uid) => `rst-r-${uid}`;
3122
+ Component.MARKER_START = (uid) => `rst-s-${uid}`;
3123
+ Component.MARKER_END = (uid) => `rst-e-${uid}`;
3113
3124
 
3114
3125
  /**
3115
3126
  * Components are a special kind of `View` that is designed to be easily composable,
@@ -3121,9 +3132,9 @@
3121
3132
  * @extends View
3122
3133
  * @param {object} options Object containing options. The following keys will be merged to `this`: model, state, key, onDestroy, onHydrate, onRecycle, onUpdate, onCreate, onChange. Any additional options not in the component or view options list will be automatically extracted as props and stored as `this.props`.
3123
3134
  * @property {string} [key] A unique key to identify the component. Components with keys are recycled when the same key is found in the previous render. Unkeyed components are recycled based on type and position.
3124
- * @property {Rasti.Model} [model] A `Rasti.Model` or any emitter object containing data and business logic. The component will listen to `change` events and call `onChange` lifecycle method.
3125
- * @property {Rasti.Model} [state] A `Rasti.Model` or any emitter object containing data and business logic, to be used as internal state. The component will listen to `change` events and call `onChange` lifecycle method.
3126
- * @property {Rasti.Model} [props] Automatically created from any options not merged to the component instance. Contains props passed from parent component as a `Rasti.Model`. The component will listen to `change` events on props and call `onChange` lifecycle method. When a component with a `key` is recycled during parent re-render, new props are automatically updated and any changes trigger a re-render.
3135
+ * @property {Model} [model] A `Model` or any emitter object containing data and business logic. The component will listen to `change` events and call `onChange` lifecycle method.
3136
+ * @property {Model} [state] A `Model` or any emitter object containing data and business logic, to be used as internal state. The component will listen to `change` events and call `onChange` lifecycle method.
3137
+ * @property {Model} [props] Automatically created from any options not merged to the component instance. Contains props passed from parent component as a `Model`. The component will listen to `change` events on props and call `onChange` lifecycle method. When a component with a `key` is recycled during parent re-render, new props are automatically updated and any changes trigger a re-render.
3127
3138
  * @see {@link #module_component_create Component.create}
3128
3139
  * @example
3129
3140
  * import { Component, Model } from 'rasti';
@@ -3134,7 +3145,7 @@
3134
3145
  * </div>
3135
3146
  * `;
3136
3147
  * // Create model to store seconds.
3137
- * const model = new Model({ seconds: 0 });
3148
+ * const model = new Model({ seconds : 0 });
3138
3149
  * // Mount timer on body.
3139
3150
  * Timer.mount({ model }, document.body);
3140
3151
  * // Increment `model.seconds` every second.