From c4e8c60376e96ceb42e4852ac09659ae9bf4bea4 Mon Sep 17 00:00:00 2001 From: alexsc6955 Date: Thu, 18 Jan 2024 08:06:55 -0500 Subject: [PATCH] Update package version and export types --- CHANGELOG.md | 4 ++++ package.json | 19 +------------------ src/core/Pubsub.ts | 4 ++-- src/core/Router.ts | 10 +++++----- src/core/buildApp/index.ts | 5 +---- src/core/buildApp/types/index.ts | 5 ++++- .../buildElement/helpers/createElement.ts | 3 ++- src/core/buildElement/helpers/getText.ts | 4 ++-- src/core/buildElement/helpers/handleEvents.ts | 3 ++- src/core/buildElement/index.ts | 10 +--------- src/core/buildElement/types/index.ts | 15 +++++++++++++++ src/index.ts | 12 ++++++++++-- 12 files changed, 49 insertions(+), 45 deletions(-) create mode 100644 src/core/buildElement/types/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf17f7..3ea88c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.4.2] - 2024-01-18 +### Changed + - Structure and module index to export types + ## [0.4.1] - 2024-01-17 ### Changed - Exports in `package.json` to include `build/buildApp/index.js` as entry point diff --git a/package.json b/package.json index 2b0211c..b1bb9ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "penrose-paradox", - "version": "0.4.1", + "version": "0.4.2", "description": "Simple vanilla JavaScript library for beginners", "keywords": [ "penrose", @@ -18,23 +18,6 @@ "module": "build/index.js", "types": "build/index.d.ts", "ts-module": "src/index.ts", - "exports": { - ".": { - "import": "./build/index.js", - "require": "./build/index.js" - }, - "./buildApp": "./build/buildApp/index.js" - }, - "typesVersions": { - "*": { - "./": [ - "build/index.d.ts" - ], - "./buildApp": [ - "build/buildApp/index.d.ts" - ] - } - }, "license": "ISC", "repository": { "type": "git", diff --git a/src/core/Pubsub.ts b/src/core/Pubsub.ts index 1ca9a76..92b78af 100644 --- a/src/core/Pubsub.ts +++ b/src/core/Pubsub.ts @@ -1,5 +1,5 @@ -type EventCallback = (data: any) => void; -type EventMap = { [key: string]: Set }; +export type EventCallback = (data: any) => void; +export type EventMap = { [key: string]: Set }; /** * PubSub class for implementing publish-subscribe pattern. */ diff --git a/src/core/Router.ts b/src/core/Router.ts index 5f71349..3b2e504 100644 --- a/src/core/Router.ts +++ b/src/core/Router.ts @@ -2,13 +2,13 @@ type RouteParams = Map; // TODO: Add array support for query params -type RouterProps = { +export type RouterProps = { queryString?: string; params?: RouteParams; baseUrl?: string; }; -type Route = { +export type Route = { path: string; component?: Function; layout?: Function; @@ -16,14 +16,14 @@ type Route = { pathSegments?: string[]; }; -type RouteList = Route[]; +export type RouteList = Route[]; -type RouterOptions = { +export type RouterOptions = { routes?: RouteList; baseUrl?: string; }; -type RouterMemo = { +export type RouterMemo = { [key: string]: string; }; diff --git a/src/core/buildApp/index.ts b/src/core/buildApp/index.ts index 04a2cf8..89dc2b9 100644 --- a/src/core/buildApp/index.ts +++ b/src/core/buildApp/index.ts @@ -3,10 +3,7 @@ import buildVirtualDOM from "./helpers/buildVirtualDOM"; import renderVirtualDOM, { targetNodeCache, setTargetNodeCache } from "./helpers/renderVirtualDOM"; import diff from "./helpers/diff"; -import { ParadoxElement, ParadoxAppFunction, ParadoxVirtualElement } from "./types"; - -type State = any; -type StateCallback = (val: any) => void; +import { ParadoxElement, ParadoxAppFunction, ParadoxVirtualElement, State, StateCallback } from "./types"; export function addState (value: any): [State, StateCallback] { let state = value; diff --git a/src/core/buildApp/types/index.ts b/src/core/buildApp/types/index.ts index 0d26891..b611415 100644 --- a/src/core/buildApp/types/index.ts +++ b/src/core/buildApp/types/index.ts @@ -27,4 +27,7 @@ export type ParadoxVirtualElement = { events?: ParadoxEvents; } | string; -export type Patch = (node: HTMLElement) => HTMLElement | Text | undefined | ParadoxVirtualElement; \ No newline at end of file +export type Patch = (node: HTMLElement) => HTMLElement | Text | undefined | ParadoxVirtualElement; + +export type State = any; +export type StateCallback = (val: any) => void; diff --git a/src/core/buildElement/helpers/createElement.ts b/src/core/buildElement/helpers/createElement.ts index 461600f..1f95b18 100644 --- a/src/core/buildElement/helpers/createElement.ts +++ b/src/core/buildElement/helpers/createElement.ts @@ -1,4 +1,5 @@ -type ParadoxElementCache = { [key: string]: HTMLElement }; +import { ParadoxElementCache } from "../types"; + const elementsCache: ParadoxElementCache = {}; /** diff --git a/src/core/buildElement/helpers/getText.ts b/src/core/buildElement/helpers/getText.ts index efc5397..a8981a4 100644 --- a/src/core/buildElement/helpers/getText.ts +++ b/src/core/buildElement/helpers/getText.ts @@ -1,5 +1,5 @@ -// Object for caching processed text values -type ParadoxElementMemoizedText = { [key: string]: string }; +import { ParadoxElementMemoizedText } from "../types"; + const memoizedText: ParadoxElementMemoizedText = {}; // Function to retrieve or compute a formatted text value diff --git a/src/core/buildElement/helpers/handleEvents.ts b/src/core/buildElement/helpers/handleEvents.ts index add4b39..8286de1 100644 --- a/src/core/buildElement/helpers/handleEvents.ts +++ b/src/core/buildElement/helpers/handleEvents.ts @@ -1,4 +1,5 @@ -type ParadoxEventListenerWeakMap = WeakMap>; +import { ParadoxEventListenerWeakMap } from '../types'; + // WeakMap to store event listeners for each element const eventListeners: ParadoxEventListenerWeakMap = new WeakMap(); diff --git a/src/core/buildElement/index.ts b/src/core/buildElement/index.ts index 0b91180..bf223ae 100644 --- a/src/core/buildElement/index.ts +++ b/src/core/buildElement/index.ts @@ -5,15 +5,7 @@ import handleEvents from "./helpers/handleEvents"; import applyStyles from "./helpers/applyStyles"; import appendChildren from "./helpers/appendChildren"; -type ParadoxElementOptions = { - id?: string; - classList?: string; - children?: ParadoxElementOptions[]; - attributes?: { [key: string]: string }; - events?: { [key: string]: EventListener }; - text?: string; - style?: { [key: string]: string }; -}; +import { ParadoxElementOptions } from "./types"; /** * Builds and returns an HTML element based on the provided tag and options. diff --git a/src/core/buildElement/types/index.ts b/src/core/buildElement/types/index.ts new file mode 100644 index 0000000..bb1dfae --- /dev/null +++ b/src/core/buildElement/types/index.ts @@ -0,0 +1,15 @@ +export type ParadoxElementOptions = { + id?: string; + classList?: string; + children?: ParadoxElementOptions[]; + attributes?: { [key: string]: string }; + events?: { [key: string]: EventListener }; + text?: string; + style?: { [key: string]: string }; +}; + +export type ParadoxEventListenerWeakMap = WeakMap>; + +export type ParadoxElementMemoizedText = { [key: string]: string }; + +export type ParadoxElementCache = { [key: string]: HTMLElement }; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index df2ba23..ccb1198 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,9 @@ import buildElement from "./core/buildElement"; -import Router from "./core/Router"; -import pubsub from "./core/Pubsub"; +import * as buildElementTypes from "./core/buildElement/types"; +import Router, * as RouterTypes from "./core/Router"; +import pubsub, * as pubsubTypes from "./core/Pubsub"; import buildApp from "./core/buildApp"; +import * as types from "./core/types"; /** * Represents the Paradox object. @@ -11,6 +13,12 @@ const Paradox = { Router, pubsub, buildApp, + types: { + buildElement: buildElementTypes, + Router: RouterTypes, + pubsub: pubsubTypes, + buildApp: types, + } }; export default Paradox; \ No newline at end of file