lilact 0.23.0 → 0.24.0

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 (41) hide show
  1. package/README.md +19 -5
  2. package/dist/lilact.development.js +490 -464
  3. package/dist/lilact.development.js.map +4 -4
  4. package/dist/lilact.development.min.js +24 -24
  5. package/dist/lilact.development.min.js.map +4 -4
  6. package/dist/lilact.production.min.js +24 -24
  7. package/docs/assets/hierarchy.js +1 -1
  8. package/docs/classes/components.Component.html +1 -1
  9. package/docs/classes/components.HTMLComponent.html +1 -1
  10. package/docs/classes/components.RootComponent.html +1 -1
  11. package/docs/functions/components.cloneComponent.html +1 -1
  12. package/docs/functions/run.lazy.html +1 -1
  13. package/docs/functions/run.require.html +3 -4
  14. package/docs/functions/run.runScripts.html +1 -1
  15. package/docs/functions/timers.timeoutPromise.html +4 -4
  16. package/docs/hierarchy.html +1 -1
  17. package/docs/index.html +21 -5
  18. package/docs/static/demos/cloneelement.jsx +6 -0
  19. package/docs/static/demos/lazy.jsx +1 -1
  20. package/docs/static/demos/legacy-context.jsx +0 -7
  21. package/docs/static/index.html +3 -3
  22. package/docs/static/lilact.development.js +490 -464
  23. package/docs/static/lilact.development.js.map +4 -4
  24. package/docs/static/lilact.development.min.js +24 -24
  25. package/docs/static/lilact.development.min.js.map +4 -4
  26. package/docs/static/lilact.production.min.js +24 -24
  27. package/docs/variables/components.cloneElement.html +1 -1
  28. package/examples/demos/cloneelement.jsx +6 -0
  29. package/examples/demos/lazy.jsx +1 -1
  30. package/examples/demos/legacy-context.jsx +0 -7
  31. package/examples/index.html +3 -3
  32. package/examples/lilact.development.js +490 -464
  33. package/examples/lilact.development.js.map +4 -4
  34. package/examples/lilact.development.min.js +24 -24
  35. package/examples/lilact.development.min.js.map +4 -4
  36. package/examples/lilact.production.min.js +24 -24
  37. package/package.json +1 -1
  38. package/src/components.jsx +3 -3
  39. package/src/lilact.jsx +1 -1
  40. package/src/proptypes.jsx +38 -0
  41. package/src/run.jsx +10 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
6
  "homepage": "https://arashkazemi.github.io/lilact/",
@@ -1142,7 +1142,7 @@ export function createComponent(entity, props={}, ...children)
1142
1142
  props.key = generateComponentKey(entity, props);
1143
1143
  props.children = children;
1144
1144
 
1145
- return { entity, props };
1145
+ return { entity, props, [CORE]: null };
1146
1146
  }
1147
1147
 
1148
1148
  /**
@@ -1208,7 +1208,7 @@ export function createPortal(children, element)
1208
1208
 
1209
1209
  export function cloneComponent(component, propsPatch, ...children)
1210
1210
  {
1211
- return { entity: component.entity, props: {...component.props, ...propsPatch, children} };
1211
+ return { entity: component.entity, props: {...component.props, ...propsPatch, children}, [CORE]: null };
1212
1212
  }
1213
1213
 
1214
1214
  export const cloneElement = cloneComponent;
@@ -1247,7 +1247,7 @@ export function memo(component)
1247
1247
  component[MEMOIZED] = true;
1248
1248
  }
1249
1249
  else {
1250
- component = { component, [MEMOIZED]: true };
1250
+ component = { component, [MEMOIZED]: true, [CORE]: null };
1251
1251
  }
1252
1252
  return component;
1253
1253
  }
package/src/lilact.jsx CHANGED
@@ -92,7 +92,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
92
92
  export const Lilact =
93
93
  {
94
94
 
95
- VERSION: "beta.23",
95
+ VERSION: "RC.1",
96
96
 
97
97
  // Configuration
98
98
 
package/src/proptypes.jsx CHANGED
@@ -28,6 +28,9 @@
28
28
 
29
29
  */
30
30
 
31
+ import { isValidComponent } from "./misc.jsx";
32
+
33
+
31
34
  function isNullOrUndefined(v) {
32
35
  return v === null || v === undefined;
33
36
  }
@@ -45,6 +48,28 @@ function defaultGetDisplayName(x) {
45
48
  return x.displayName || x.name || "Unknown";
46
49
  }
47
50
 
51
+
52
+ // ---- node validator ----
53
+ function isNode(x) {
54
+ // ignored-by-render children should be accepted by node
55
+ if (x === null || x === undefined) return true;
56
+ if (x === false || x === true) return true;
57
+
58
+ // primitives render
59
+ if (typeof x === "string" || typeof x === "number") return true;
60
+
61
+ if (isValidComponent(x)) return true;
62
+
63
+ // arrays are accepted as children; renderer will flatten later
64
+ if (Array.isArray(x)) return x.every(isNode);
65
+
66
+ return false;
67
+ }
68
+
69
+ function isValidElementType(x) {
70
+ return typeof x === "function" || typeof x === "string";
71
+ }
72
+
48
73
  /**
49
74
  * Build a prop validator with a consistent contract:
50
75
  * validator(props, propName, componentName, location, propFullName)
@@ -117,6 +142,19 @@ function createPropTypes() {
117
142
  PropTypes.symbol = createPrimitiveValidator((v) => typeof v === "symbol");
118
143
  PropTypes.symbol.expectedType = "symbol";
119
144
 
145
+ PropTypes.component = createPrimitiveValidator((v) => isValidComponent(v));
146
+ PropTypes.component.expectedType = "component";
147
+
148
+ PropTypes.element = createPrimitiveValidator((v) => isValidComponent(v));
149
+ PropTypes.element.expectedType = "element";
150
+
151
+ PropTypes.node = createPrimitiveValidator((v) => isNode(v));
152
+ PropTypes.node.expectedType = "node";
153
+
154
+ PropTypes.elementType = createPrimitiveValidator((v) => isValidElementType(v));
155
+ PropTypes.elementType.expectedType = "elementType";
156
+
157
+
120
158
  // ----- combinators -----
121
159
 
122
160
  PropTypes.oneOf = function oneOf(values) {
package/src/run.jsx CHANGED
@@ -147,25 +147,25 @@ if(DEBUG) {
147
147
  * @param path - The path to the required file. Must be either absolute path or relative to the current
148
148
  * module or document’s URL (the page/location that initiated the request).
149
149
  *
150
- * @param [forceUpdate] - Force re-run module. By default an imported module is only run once.
151
- *
152
- * @param [checkExport] - An array of module properties to be checked upon import. This is used for import error detection.
153
- *
154
- * @param [isLazy] - if loading is should be async. Returns a promise if true.
155
- *
156
- * @param [requirer] - The module that is importing the other module. This is used internally to resolve relative paths.
157
- *
158
150
  * @returns An array representation of the children.
159
151
  */
160
- export function require(path, {forceUpdate, checkExport, requirer, isLazy})
152
+ export function require(path)
161
153
  {
154
+ let forceUpdate, checkExport, requirer, isLazy;
155
+
156
+ // note: instead of named props, just to bypass typedoc.
157
+ if(arguments.length===2 && typeof(arguments[1]==='object')) {
158
+ forceUpdate = arguments[1]?.forceUpdate;
159
+ checkExport = arguments[1]?.checkExport;
160
+ requirer = arguments[1]?.requirer;
161
+ isLazy = arguments[1]?.isLazy;
162
+ }
162
163
 
163
164
  if(Lilact.importObjectPaths?.[path]) return Lilact.importObjectPaths[path];
164
165
  if(required_scripts[path] && !forceUpdate) return required_scripts[path].exports;
165
166
 
166
167
 
167
168
  if(path[0]==='#') {
168
-
169
169
  const el = document.getElementById(path);
170
170
 
171
171
  if(el) {
@@ -188,7 +188,6 @@ export function require(path, {forceUpdate, checkExport, requirer, isLazy})
188
188
  })
189
189
  .then(res => {
190
190
  res = run(res, path, false);
191
- // todo: this is for the lazy, so we detect default to match react behaviour, but should we do it in sync mode too?
192
191
  return res?.default ?? res;
193
192
  })
194
193
  .catch(err => {