@collagejs/core 0.1.1 → 0.1.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.
@@ -1,10 +1,18 @@
1
1
  import { MountedPiece } from "./MountedPiece.js";
2
- import type { CorePiece } from "./types.js";
3
- export declare function mountPieceCore<TProps extends Record<string, any> = Record<string, any>>(this: MountedPiece | undefined, piece: CorePiece<TProps> | Promise<CorePiece<TProps>>, target: HTMLElement, props?: TProps): Promise<MountedPiece<TProps>>;
2
+ import type { CorePiece, MountPiece } from "./types.js";
3
+ /**
4
+ * Constructor type for MountedPiece classes.
5
+ *
6
+ * This exists merely to allow unit testing.
7
+ */
8
+ export interface MountedPieceConstructor {
9
+ new <TProps extends Record<string, any> = Record<string, any>>(piece: CorePiece<TProps>, mountPiece: MountPiece<any>, parent?: MountedPiece<any>): MountedPiece<TProps>;
10
+ }
11
+ export declare function mountPieceCore<TProps extends Record<string, any> = Record<string, any>>(this: MountedPiece | undefined, piece: CorePiece<TProps> | Promise<CorePiece<TProps>>, target: HTMLElement, props?: TProps, MountedPieceClass?: MountedPieceConstructor): Promise<MountedPiece<TProps>>;
4
12
  /**
5
13
  * Mounts the CollageJS piece as a child of the target element.
6
14
  * @param piece The CollageJS piece to mount.
7
15
  * @param target The target element to mount the piece to.
8
16
  * @param props The properties to pass to the piece.
9
17
  */
10
- export declare function mountPiece<TProps extends Record<string, any> = Record<string, any>>(piece: CorePiece<TProps>, target: HTMLElement, props?: TProps): Promise<import("./types.js").MountedPiece<TProps>>;
18
+ export declare function mountPiece<TProps extends Record<string, any> = Record<string, any>>(piece: CorePiece<TProps>, target: HTMLElement, props?: TProps): Promise<MountedPiece<TProps>>;
@@ -1,9 +1,9 @@
1
1
  import { MountedPiece, mountKey } from "./MountedPiece.js";
2
- export async function mountPieceCore(piece, target, props) {
2
+ export async function mountPieceCore(piece, target, props, MountedPieceClass = MountedPiece) {
3
3
  if (piece instanceof Promise) {
4
4
  piece = await piece;
5
5
  }
6
- const mp = new MountedPiece(piece, (mountPieceCore), this);
6
+ const mp = new MountedPieceClass(piece, (mountPieceCore), this);
7
7
  await mp[mountKey](target, props);
8
8
  return mp;
9
9
  }
@@ -14,5 +14,5 @@ export async function mountPieceCore(piece, target, props) {
14
14
  * @param props The properties to pass to the piece.
15
15
  */
16
16
  export function mountPiece(piece, target, props) {
17
- return (mountPieceCore.bind(undefined))(piece, target, props);
17
+ return mountPieceCore.call(undefined, piece, target, props);
18
18
  }
package/dist/types.d.ts CHANGED
@@ -22,4 +22,4 @@ export interface MountedPiece<TProps extends Record<string, any> = Record<string
22
22
  unmount: UnmountFn;
23
23
  mountPiece: MountPiece<TProps>;
24
24
  }
25
- export type MountPiece<TProps extends Record<string, any> = Record<string, any>> = (piece: CorePiece<TProps>, target: HTMLElement, props?: TProps) => Promise<MountedPiece<TProps>>;
25
+ export type MountPiece<TProps extends Record<string, any> = Record<string, any>> = (piece: CorePiece<TProps> | Promise<CorePiece<TProps>>, target: HTMLElement, props?: TProps) => Promise<MountedPiece<TProps>>;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@collagejs/core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Core functionality for CollageJS.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
8
- "test": "npm run test:unit && npm run test:types",
8
+ "test": "npm run check && npm run test:unit && npm run test:types",
9
9
  "test:unit": "ts-mocha -n loader=ts-node/esm -p ./tsconfig.json --require ./tests/setup.ts ./tests/ut/**/*.test.ts",
10
10
  "test:watch": "ts-mocha -n loader=ts-node/esm -p ./tsconfig.json --require ./tests/setup.ts ./tests/ut/**/*.test.ts --watch",
11
11
  "test:types": "tstyche ./tests/typetests",