Skip to content

Commit

Permalink
feat: V1 draft of docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChronicStone committed Apr 23, 2024
1 parent af60a69 commit 9deeb67
Show file tree
Hide file tree
Showing 23 changed files with 2,142 additions and 106 deletions.
49 changes: 36 additions & 13 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
{
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
{
"rule": "style/*",
"severity": "off"
},
{
"rule": "*-indent",
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
Expand Down
54 changes: 40 additions & 14 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { defineConfig } from 'vitepress'
import { transformerTwoslash } from 'vitepress-plugin-twoslash'
import container from 'markdown-it-container'
import { renderSandbox } from 'vitepress-plugin-sandpack'
import Unocss from 'unocss/vite'

// https://vitepress.dev/reference/site-config
export default defineConfig({
Expand All @@ -13,12 +16,26 @@ export default defineConfig({
codeTransformers: [
transformerTwoslash(),
],
config(md) {
md
.use(container, 'sandbox', {
render(tokens, idx) {
return renderSandbox(tokens, idx, 'sandbox')
},
})
.use(container, 'code-sandbox', {
render(tokens, idx) {
return renderSandbox(tokens, idx, 'code-sandbox')
},
})
},
},
lastUpdated: true,
ignoreDeadLinks: true,
cleanUrls: true,
titleTemplate: ':title - Typed-xlsx',
titleTemplate: 'Typed-xlsx | :title',
themeConfig: {
aside: true,
logo: '/images/logo.png',
editLink: {
pattern: 'https://github.com/ChronicStone/typed-xlsx/edit/main/docs/:path',
Expand Down Expand Up @@ -47,31 +64,40 @@ export default defineConfig({
{
text: 'Schema Builder',
items: [
{ text: 'Columns', link: '/schema-builder/columns' },
{ text: 'Create schema', link: '/schema-builder/create-schema' },
{ text: 'Define columns', link: '/schema-builder/columns' },
{ text: 'Dynamic Columns', link: '/schema-builder/dynamic-columns' },
{ text: 'Global Transformers', link: '/schema-builder/global-transformers' },
{ text: 'Build Schema', link: '/schema-builder/build-schema' },
],
},
{
text: 'Column Definition',
items: [
{ text: 'Header', link: '/column-definition/header' },
{ text: 'Value Transformation', link: '/column-definition/value-transformation' },
{ text: 'Key & Value', link: '/column-definition/key-value' },
{ text: 'Default Value', link: '/column-definition/default-value' },
{ text: 'Cell Format', link: '/column-definition/cell-format' },
{ text: 'Cell Style', link: '/column-definition/cell-style' },
{ text: 'Summary', link: '/column-definition/summary' },
],
},
// {
// text: 'Column Definition',
// items: [
// { text: 'Header', link: '/column-definition/header' },
// { text: 'Value Transformation', link: '/column-definition/value-transformation' },
// { text: 'Key & Value', link: '/column-definition/key-value' },
// { text: 'Default Value', link: '/column-definition/default-value' },
// { text: 'Cell Format', link: '/column-definition/cell-format' },
// { text: 'Cell Style', link: '/column-definition/cell-style' },
// { text: 'Summary', link: '/column-definition/summary' },
// ],
// },
{
text: 'File Builder',
items: [
{ text: 'Create file builder', link: '/file-builder/create-file-builder' },
{ text: 'Define Sheets', link: '/file-builder/define-sheets' },
{ text: 'Define Tables', link: '/file-builder/define-tables' },
{ text: 'Build excel file', link: '/file-builder/build-excel-file' },
],
},
],
},
vite: {
plugins: [
// @ts-expect-error unknown ts issue
Unocss({}),
],
},
})
29 changes: 29 additions & 0 deletions docs/.vitepress/theme/components/CodeSandbox.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script setup lang="ts">
import { Sandbox, sandboxProps } from 'vitepress-plugin-sandpack'
const props = defineProps(sandboxProps)
</script>

<template>
<Sandbox
:template="template"
:light-theme="lightTheme"
:dark-theme="darkTheme"
:options="{
...props, // do not forget it
hideEditor: true,
showLineNumbers: true,
}"
:hide-editor="true"
:custom-setup="{
...props, // do not forget it
deps: {
'@chronicstone/typed-xlsx': 'latest',
'x-data-spreadsheet': 'latest',
},
}"
:code-options="codeOptions"
>
<slot />
</Sandbox>
</template>
14 changes: 12 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ import TwoslashFloatingVue from 'vitepress-plugin-twoslash/client'
import 'vitepress-plugin-twoslash/style.css'
import type { EnhanceAppContext } from 'vitepress'
import './style.css'
import 'vitepress-plugin-sandpack/dist/style.css'
import { Sandbox } from 'vitepress-plugin-sandpack'
import vitepressNprogress from 'vitepress-plugin-nprogress'
import CodeSandbox from './components/CodeSandbox.vue'
import 'vitepress-plugin-nprogress/lib/css/index.css'
import 'uno.css'

export default {
...DefaultTheme,
enhanceApp({ app }: EnhanceAppContext) {
app.use(TwoslashFloatingVue)
enhanceApp(ctx: EnhanceAppContext) {
ctx.app.use(TwoslashFloatingVue)
DefaultTheme.enhanceApp?.(ctx)
vitepressNprogress(ctx)
ctx.app.component('Sandbox', Sandbox)
ctx.app.component('CodeSandbox', CodeSandbox)
},
}
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ body {
.VPHero.has-image .image {
display: none;
}
}
}
122 changes: 122 additions & 0 deletions docs/file-builder/build-excel-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Build Excel File

After defining the sheets and tables, the final step is to build the Excel file using the `build()` method. This method allows you to specify various parameters to customize the output. Here's a detailed explanation of each parameter:

## Build Method

To build the Excel file, call the `build()` method on the ExcelBuilder instance :

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer' })
```

## Parameters

### `output`
- **Description:** Specifies the format of the output.
- **Type:** `'buffer' | 'workbook' | 'base64' | 'file'`
- **Required:** Yes
- **Example:**
```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const buffer = ExcelBuilder.create()
// ^?
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer' })

const workbook = ExcelBuilder.create()
// ^?
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'workbook' })

const base64 = ExcelBuilder.create()
// ^?
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'base64' })

const file = ExcelBuilder.create()
// ^?
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'file' })
```


### `rtl`
- **Description:** Specifies whether the Excel file should be rendered in right-to-left (RTL) mode.
- **Type:** `boolean`
- **Required:** No
- **Default:** `false`
- **Example:**


```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer', rtl: true })
```

### `extraLength`
- **Description:** Specifies the extra length each cell should be rendered with.
- **Type:** `number`
- **Required:** No
- **Default:** `10`
- **Example:**

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer', extraLength: 5 })
```

### `rowHeight`
- **Description:** Specifies the height of each row in the Excel file.
- **Type:** `number`
- **Required:** No
- **Default:** `30`
- **Example:**

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer', rowHeight: 30 })
```

### `bordered`
- **Description:** Specifies whether the Excel file should have borders.
- **Type:** `boolean`
- **Required:** No
- **Default:** `true`
- **Example:**

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer', bordered: false })
52 changes: 52 additions & 0 deletions docs/file-builder/create-file-builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Create File Builder

To construct an Excel file with `typed-xlsx`, start by creating an instance of the file builder using `ExcelBuilder`. This class facilitates the construction of Excel files through a method chaining approach that allows you to configure properties and behaviors sequentially.

## Importing ExcelBuilder

First, ensure that `ExcelBuilder` is imported from the `typed-xlsx` package:

```ts twoslash
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
```

## Creating an ExcelBuilder Instance

To start building an Excel file, create a new instance of ExcelBuilder by calling create(). This method initializes a new Excel file builder instance:

```ts twoslash
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
```

## Method Chaining

ExcelBuilder utilizes method chaining to streamline the configuration of your Excel file, to preserve type-safety and ensure consistency.

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.build({ output: 'buffer' })
```

## Multiple Sheets

In typed-xlsx, you can define multiple sheets in a single workbook. You just need to chain the method calls for each sheet you want to add:

```ts twoslash
// @noErrors
import { ExcelBuilder } from '@chronicstone/typed-xlsx'
// ---cut-before---
const excelFile = ExcelBuilder.create()
.sheet('Sheet1')
.addTable({ data, schema, })
.sheet('Sheet2')
.addTable({ data, schema, })
.build({ output: 'buffer' })
```

Loading

0 comments on commit 9deeb67

Please sign in to comment.