nesquick 1.5.0 → 2.0.2

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/lib/For/For.js CHANGED
@@ -85,7 +85,7 @@ function For(props) {
85
85
  const map = getCycleMap(props);
86
86
  (0, State_1.useRender)(() => {
87
87
  cycle = !cycle;
88
- const each = props.each().slice();
88
+ const each = props.each.slice();
89
89
  if (children.length === 0) {
90
90
  for (let i = 0; i < each.length; i++) {
91
91
  const item = each[i];
package/lib/For/getMap.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMap = getMap;
4
4
  function getMap(props) {
5
- const idsCallback = "ids" in props && props.ids?.();
5
+ const idsCallback = "ids" in props && props.ids;
6
6
  if (idsCallback) {
7
7
  const childrenMap = new Map();
8
8
  let idLength = 0;
@@ -78,7 +78,7 @@ function getMap(props) {
78
78
  }
79
79
  else {
80
80
  const childrenMap = new Map();
81
- const idCallback = "id" in props && props.id?.() || (item => item);
81
+ const idCallback = "id" in props && props.id || (item => item);
82
82
  return {
83
83
  getId: idCallback,
84
84
  equalsId(a, b) {
@@ -21,6 +21,17 @@ function getAttributeNs(attributes, k) {
21
21
  }
22
22
  return null;
23
23
  }
24
+ function getterFromFunctions(props) {
25
+ const res = Object.create(null);
26
+ for (const k in props) {
27
+ Object.defineProperty(res, k, {
28
+ get() {
29
+ return props[k]();
30
+ }
31
+ });
32
+ }
33
+ return res;
34
+ }
24
35
  class NesquickComponent {
25
36
  constructor(_render, props) {
26
37
  this._render = _render;
@@ -33,6 +44,7 @@ class NesquickComponent {
33
44
  render(document) {
34
45
  State_1.subscriptions.set(this._subscriptions);
35
46
  if (typeof this._render === "function") {
47
+ this.props = getterFromFunctions(this.props);
36
48
  const element = this._render(this.props);
37
49
  if (this._xmlns) {
38
50
  element.setXmlns(this._xmlns);
@@ -4,9 +4,7 @@ exports.NesquickFragment = void 0;
4
4
  const NesquickComponent_1 = require("./NesquickComponent");
5
5
  class NesquickFragment extends NesquickComponent_1.NesquickComponent {
6
6
  constructor(children) {
7
- super("", {
8
- children: children != null ? Array.isArray(children) ? children : [children] : []
9
- });
7
+ super("", { children });
10
8
  this._lastNode = null;
11
9
  this._fragment = null;
12
10
  }
@@ -34,6 +34,9 @@ function createSpreadCheckFunction(fName) {
34
34
  TS.factory.createParameterDeclaration(void 0, void 0, obj),
35
35
  TS.factory.createParameterDeclaration(void 0, void 0, check)
36
36
  ], void 0, TS.factory.createBlock([
37
+ TS.factory.createIfStatement(TS.factory.createPrefixUnaryExpression(TS.SyntaxKind.ExclamationToken, obj), TS.factory.createBlock([
38
+ TS.factory.createReturnStatement(obj)
39
+ ], true), void 0),
37
40
  TS.factory.createVariableStatement(void 0, TS.factory.createVariableDeclarationList([
38
41
  TS.factory.createVariableDeclaration(res, void 0, void 0, TS.factory.createCallExpression(TS.factory.createPropertyAccessExpression(TS.factory.createIdentifier("Object"), "create"), void 0, [TS.factory.createNull()]))
39
42
  ], TS.NodeFlags.Const)),
@@ -73,6 +76,12 @@ const transformer = context => {
73
76
  node = TS.factory.updateJsxSpreadAttribute(node, callExpression);
74
77
  }
75
78
  }
79
+ else if (TS.isJsxElement(node)) {
80
+ const firstLetter = node.openingElement.tagName.getText()[0];
81
+ const userComponent = firstLetter !== firstLetter.toLowerCase();
82
+ const res = processNode(node, { userComponent });
83
+ node = res.node;
84
+ }
76
85
  else if (TS.isJsxOpeningLikeElement(node)) {
77
86
  const firstLetter = node.tagName.getText()[0];
78
87
  const userComponent = firstLetter !== firstLetter.toLowerCase();
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JSX = exports.jsx = exports.Fragment = void 0;
3
+ exports.JSX = exports.Fragment = void 0;
4
4
  exports.jsxs = jsxs;
5
+ exports.jsx = jsx;
5
6
  const NesquickComponent_1 = require("./NesquickComponent");
6
7
  const NesquickFragment_1 = require("./NesquickFragment");
7
8
  exports.Fragment = Symbol();
@@ -14,7 +15,15 @@ function jsxs(type, props, key) {
14
15
  }
15
16
  return new NesquickComponent_1.NesquickComponent(type, props);
16
17
  }
17
- exports.jsx = jsxs;
18
+ function jsx(type, props, key) {
19
+ if (type === exports.Fragment) {
20
+ return new NesquickFragment_1.NesquickFragment([props.children]);
21
+ }
22
+ if (key !== undefined) {
23
+ props.key = key;
24
+ }
25
+ return new NesquickComponent_1.NesquickComponent(type, props);
26
+ }
18
27
  var JSX;
19
28
  (function (JSX) {
20
29
  })(JSX || (exports.JSX = JSX = {}));
@@ -1,4 +1,4 @@
1
- import { Props, JSX } from "../Nesquick";
1
+ import { JSX } from "../Nesquick";
2
2
  import { NesquickFragment } from "../NesquickFragment";
3
3
  type ChildRender<T> = (item: T, i: () => number) => JSX.Element;
4
4
  export type ForProps<T> = {
@@ -14,5 +14,5 @@ export type ForProps<T> = {
14
14
  ids?: never;
15
15
  id?: never;
16
16
  });
17
- export declare function For<T>(props: Props<ForProps<T>>): NesquickFragment;
17
+ export declare function For<T>(props: ForProps<T>): NesquickFragment;
18
18
  export {};
@@ -1,4 +1,3 @@
1
- import { Props } from "../Nesquick";
2
1
  import { ForProps } from "./For";
3
2
  export type IdMap<T, ID, CHILD> = {
4
3
  getId(item: T, i: number): ID;
@@ -8,11 +7,11 @@ export type IdMap<T, ID, CHILD> = {
8
7
  deleteChild(id: ID): void;
9
8
  clearChilds(): void;
10
9
  };
11
- type IdMapProps<T> = Props<Pick<Extract<ForProps<T>, {
10
+ type IdMapProps<T> = Pick<Extract<ForProps<T>, {
12
11
  id?: unknown;
13
12
  }>, "id"> | Pick<Extract<ForProps<T>, {
14
13
  ids?: unknown;
15
- }>, "ids">>;
14
+ }>, "ids">;
16
15
  export declare function getMap<T, CHILD>(props: Required<Extract<IdMapProps<T>, {
17
16
  id?: unknown;
18
17
  }>>): IdMap<T, unknown, CHILD>;
@@ -1,11 +1,11 @@
1
1
  import { JSX } from "./Nesquick";
2
- import { Child, Children, NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
2
+ import { Child, NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
3
3
  export declare class NesquickFragment extends NesquickComponent<{
4
4
  children: Child[];
5
5
  }> implements NesquickParent {
6
6
  private _lastNode;
7
7
  private _fragment;
8
- constructor(children: Children);
8
+ constructor(children: Child[]);
9
9
  render(document: VeactDocument): Node;
10
10
  getDocument(): Document | null;
11
11
  getParent(): Node | null;
@@ -2,25 +2,8 @@ import { FunctionComponent, ComponentProps, NesquickComponent } from "./Nesquick
2
2
  import { NesquickFragment } from "./NesquickFragment";
3
3
  export declare const Fragment: unique symbol;
4
4
  export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
5
- export declare const jsx: typeof jsxs;
6
- type HasUndefined<T, K extends keyof T> = {
7
- [L in K]-?: T[L] | undefined;
8
- } extends {
9
- [L in K]?: T[L];
10
- } ? undefined extends T[K] ? true : false : false;
11
- declare const WrappedFunctionType: unique symbol;
12
- type WrappedFunction<T> = (() => T) & {
13
- readonly [WrappedFunctionType]?: T;
14
- };
15
- type UserProps<T> = {
16
- readonly [K in keyof T]: K extends keyof JSX.ElementChildrenAttribute ? T[K] : WrappedFunction<HasUndefined<T, K> extends true ? T[K] : Exclude<T[K], undefined>>;
17
- };
18
- type JSXProp<T> = T extends WrappedFunction<infer R> ? R : T;
19
- type JSXProps<T> = keyof T extends never ? {} : {
20
- [K in keyof T]: JSXProp<T[K]>;
21
- };
22
- export { UserProps as Props };
23
- export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
5
+ export declare function jsx<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
6
+ export type Component<P extends Record<any, any> = {}> = (props: P) => JSX.Element;
24
7
  export declare namespace JSX {
25
8
  export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
26
9
  currentTarget: T2;
@@ -60,6 +43,5 @@ export declare namespace JSX {
60
43
  export interface ElementChildrenAttribute {
61
44
  children: {};
62
45
  }
63
- export type LibraryManagedAttributes<_, P> = JSXProps<P>;
64
46
  export {};
65
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "1.5.0",
3
+ "version": "2.0.2",
4
4
  "description": "React-like library with focus on drawing performance",
5
5
  "types": "./lib/types/index.d.ts",
6
6
  "main": "./lib/index.js",