From ee11f72c12d30d5a7aadacc0426e5c125b7bfec0 Mon Sep 17 00:00:00 2001 From: alexanderkalachev Date: Thu, 28 Nov 2024 17:28:03 +0500 Subject: [PATCH] Updating documentatio for all packages --- README.md | 13 +++++ packages/@weresk/locales/CHANGELOG.md | 6 +++ packages/@weresk/locales/README.md | 16 ++++-- packages/@weresk/locales/package.json | 2 +- packages/@weresk/maket/CHANGELOG.md | 8 +++ packages/@weresk/maket/README.md | 1 + packages/@weresk/maket/package.json | 2 +- packages/@weresk/router/CHANGELOG.md | 6 +++ packages/@weresk/router/README.md | 51 ++++++++++++++++++- packages/@weresk/router/package.json | 2 +- .../@weresk/router/src/utils/getLinkType.ts | 10 ++-- 11 files changed, 104 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3d61fdd..4c26d6b 100755 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ # Weresk Libraries + +Toolkit for bulding website with Next.js, Sanity and Tailwind + +# Packages + +- **`@weresk/core`**: Common utilities and types for the rest of @weresk libraries + - [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/core/README.md) +- **`@weresk/locales`**: Toolkit for Next.js app localization + - [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/locales/README.md) +- **`@weresk/links`**: Toolkit for working with links in Next.js app + - [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/router/README.md) +- **`@weresk/maket`**: Toolkit for working with grid, typography and swatches in TailwindCSS + - [Documentation](https://github.com/alexanderkalachev/weresk/blob/main/packages/%40weresk/maket/README.md) diff --git a/packages/@weresk/locales/CHANGELOG.md b/packages/@weresk/locales/CHANGELOG.md index 39cff40..11f56a8 100644 --- a/packages/@weresk/locales/CHANGELOG.md +++ b/packages/@weresk/locales/CHANGELOG.md @@ -1,5 +1,11 @@ # @weresk/locales +## 0.0.5 + +### Patch Changes + +- Updating a documentation + ## 0.0.4 ### Patch Changes diff --git a/packages/@weresk/locales/README.md b/packages/@weresk/locales/README.md index 1a59fde..51aa23d 100644 --- a/packages/@weresk/locales/README.md +++ b/packages/@weresk/locales/README.md @@ -11,12 +11,20 @@ Toolkit for Next.js app localization - **`languages: {id: string, title: string}[]`**: List of languages - **Returns**: **`ReturnType[]`** +## Constants + +- **`ISO_LOCALES`**: Array of language codes from ISO 639 + ## Types -- **`LocaleProps`**: Adds `lang` property to a props interface -- **`LocaleString`**: Localized string object -- **`LocaleObject`**: Localized any type object -- **`LocalizationConfig`**: Localization config definition +- **`IsoLocale`**: Type literal string with language codes from ISO 639 +- **`LocaleProps`**: Adds optional `lang` property to a props interface +- **`LocaleString = Partial>`**: Localized string object +- **`LocaleObject`**: Localized any type object +- **`LocalizationConfig`**: Localization config definition + - **`languages: {id: Locale; title: string; abbr: string;}[]`**: List of languages + - **`defaultLocale: Locale`**: ID of a default language + - **`safeReplace?: boolean`**: Sets if a default locale should be used if a desired language value is missing ## Utils diff --git a/packages/@weresk/locales/package.json b/packages/@weresk/locales/package.json index 99e8790..ecad492 100755 --- a/packages/@weresk/locales/package.json +++ b/packages/@weresk/locales/package.json @@ -1,6 +1,6 @@ { "name": "@weresk/locales", - "version": "0.0.4", + "version": "0.0.5", "private": false, "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/packages/@weresk/maket/CHANGELOG.md b/packages/@weresk/maket/CHANGELOG.md index 777d411..4951a8e 100644 --- a/packages/@weresk/maket/CHANGELOG.md +++ b/packages/@weresk/maket/CHANGELOG.md @@ -1,5 +1,13 @@ # @weresk/maket +## 0.2.6 + +### Patch Changes + +- Updating documentation +- Updated dependencies + - @weresk/locales@0.0.5 + ## 0.2.5 ### Patch Changes diff --git a/packages/@weresk/maket/README.md b/packages/@weresk/maket/README.md index 83cfe2e..dd63869 100755 --- a/packages/@weresk/maket/README.md +++ b/packages/@weresk/maket/README.md @@ -1,4 +1,5 @@ **@weresk/maket** +Toolkit for working with grid, typography and swatches in TailwindCSS # Config Documentation diff --git a/packages/@weresk/maket/package.json b/packages/@weresk/maket/package.json index 0f7b937..fa93ce4 100755 --- a/packages/@weresk/maket/package.json +++ b/packages/@weresk/maket/package.json @@ -1,6 +1,6 @@ { "name": "@weresk/maket", - "version": "0.2.5", + "version": "0.2.6", "private": false, "exports": { ".": { diff --git a/packages/@weresk/router/CHANGELOG.md b/packages/@weresk/router/CHANGELOG.md index b3c1a78..70ba525 100644 --- a/packages/@weresk/router/CHANGELOG.md +++ b/packages/@weresk/router/CHANGELOG.md @@ -1,5 +1,11 @@ # @weresk/router +## 0.0.3 + +### Patch Changes + +- Adding documentation + ## 0.0.2 ### Patch Changes diff --git a/packages/@weresk/router/README.md b/packages/@weresk/router/README.md index be18fa1..0c1be34 100644 --- a/packages/@weresk/router/README.md +++ b/packages/@weresk/router/README.md @@ -1,4 +1,53 @@ **@weresk/router** Toolkit for working with links in Next.js app ---- +# Exports + +## Types + +- **Schemas** + - **`linkTyped({router: RouterConfig, localization?: LocalizationConfig})`**: Link with manual selection between link types: reference, anchor, external, internal or file + - **`linkExternal({router: RouterConfig, localization?: LocalizationConfig})`**: Link with a caption and external URL + - **`linkCaptioned({router: RouterConfig, localization?: LocalizationConfig})`**: Link with a caption and typed link + - **`linkContact({router: RouterConfig, localization?: LocalizationConfig})`**: Typed contact link + - **`normalizedSlug({router: RouterConfig, localization?: LocalizationConfig})`**: Slug schema with slugify and isUnique functions set + - **`routerObjects({router: RouterConfig, localization?: LocalizationConfig})`**: Generates an array of schema definitions with all types listed above + +## Types + +- **Props** + - **`ReferenceDocument`**: Base Sanity document type with title, slug and optional parent + - **`RouterSchemaProps`**: Props for router schemas definition + - **`RouterConfig`**: Router config object + - `mode: "parent" | "folder"`: Defines what strategy is used for pages structure: + - `parent`: Documents are nested under the parent document like `/parents-parent/parent/slug` + - `folder`: Documents are grouped inside the folder determined by document type, using `routes` configuration, like `/folder/slug` + - `schemas: string[]`: Link of document schemas that can be referenced in links + - `routes: Record`: Object with document types as keys and folder names as values to use in `folder` mode + - `contacts?: ContactType[]`: Optional customization of contacts types for `linkContact` schema + - `parentDepth?: number`: Optional customization of nesting depth limit used in `parent` mode + +## Utils + +- **`getDocumentPath(doc: ReferenceDocument | undefined, config: RouterConfig): string`**: Generates URL for a document +- **`getLinkType(url: string): LinkType`**: Checks the link type for a URL +- **`getTypesWithSameRoute(docType: string | undefined, routes: Record): string[]`**: Finds the documents types that have the route similar to a singular document type +- **`isUniqueSlugFunction(config: RouterConfig): (slug: string, context: SlugValidationContext) => Promise`**: Generates isUniqueSlug function based on router config +- **`normalizeLink(input: string): string`**: Normalizes a string to be used as a URL +- **`prepareLink(input: LinkTyped, router: RouterConfig, lang?: IsoLocale): string`**: Generates an URL from a `LinkTyped` object +- **`wrapReference(doc: ReferenceDocument): LinkTyped`**: Converts a document type into `LinkTyped` + +## Components + +- **`LinkWrapper`**: A wrapper function to render a Next.js link from router schemas like typed link, reference and href + - **Props: `LinkWrapperProps extends LocaleProps`** + - **`href?: string`**: URL, is set used first + - **`reference?: ReferenceDocument`**: Refefence to a document, if set used before the `link` + - **`link?: LinkTyped`**: Typed link + - **`title?: string`**: `title` property for rendered HTML element + - **`config: RouterConfig`**: Router configuration +- **`ContactLink`**: Renders contact link as a text or as an icon + - **Props: `ContactLinkProps extends LocaleProps`** + - **`link: LinkContact`**: Contact type identifier + - **`mode: "text" | "icon"`**: Render mode + - **`config: RouterConfig`**: Router configuration diff --git a/packages/@weresk/router/package.json b/packages/@weresk/router/package.json index 40cf82c..0e8a54a 100755 --- a/packages/@weresk/router/package.json +++ b/packages/@weresk/router/package.json @@ -1,6 +1,6 @@ { "name": "@weresk/router", - "version": "0.0.2", + "version": "0.0.3", "private": false, "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/packages/@weresk/router/src/utils/getLinkType.ts b/packages/@weresk/router/src/utils/getLinkType.ts index 9009c3c..24bec31 100644 --- a/packages/@weresk/router/src/utils/getLinkType.ts +++ b/packages/@weresk/router/src/utils/getLinkType.ts @@ -1,13 +1,13 @@ import { LinkType } from "../schemas"; -export function getLinkType(input: string): LinkType { - if (input.startsWith("#")) { +export function getLinkType(url: string): LinkType { + if (url.startsWith("#")) { return "anchor"; } if ( - input.startsWith("http://") || - input.startsWith("https://") || - input.startsWith("mailto:" || input.startsWith("www.")) + url.startsWith("http://") || + url.startsWith("https://") || + url.startsWith("mailto:" || url.startsWith("www.")) ) { return "external"; }