Skip to content

Commit

Permalink
Merge pull request #18 from jacob-8/integrated-kitbook
Browse files Browse the repository at this point in the history
Integrated kitbook
  • Loading branch information
jacob-8 authored Sep 13, 2023
2 parents 70e3486 + 5c02802 commit 0014458
Show file tree
Hide file tree
Showing 126 changed files with 2,255 additions and 2,080 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
link-workspace-packages=false
# link-workspace-packages=false
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"antfu.unocss",
// Code quality
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
// Git
"eamodio.gitlens",
"github.vscode-pull-request-github",
Expand Down
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799"
},
"files.associations": {},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.associations": {
"*.svx": "svelte"
},
"css.lint.unknownAtRules": "ignore",
"vitest.enable": true,
"foam.edit.linkReferenceDefinitions": "withExtensions",
"foam.files.ignore": [
"**/node_modules/**/*",
"**/package/**/*",
"**/.svelte-kit/**/*",
"**/dist/**/*",
],
"foam.completion.label": "title",
"svelte.plugin.svelte.compilerWarnings": {
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@
"pieces:preview": "pnpm --filter=svelte-pieces preview",
"pieces:test": "pnpm --filter=svelte-pieces test",
"template": "pnpm --filter=template dev",
"template:kitbook": "pnpm --filter=template kitbook",
"template:build": "pnpm --filter=template build",
"release": "pnpm build:deps && pnpm test && changeset publish",
"check-packages": "pnpm update --interactive --recursive --latest"
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
"@changesets/cli": "^2.26.2",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-svelte": "^2.31.1",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.0.0",
"typescript": "~5.1.5",
"vite": "^4.3.9",
"vitest": "^0.32.2"
"svelte": "^4.2.0",
"typescript": "~5.2.2",
"vite": "^4.4.9",
"vitest": "^0.34.4"
},
"type": "module"
}
16 changes: 8 additions & 8 deletions packages/experiment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/kit": "^1.20.5",
"@sveltejs/package": "^2.1.0",
"svelte": "^4.0.0",
"svelte-check": "^3.4.4",
"tslib": "^2.5.3",
"typescript": "^5.1.5",
"vite": "^4.3.9",
"vite-plugin-inspect": "^0.7.29"
"@sveltejs/kit": "^1.24.1",
"@sveltejs/package": "^2.2.2",
"svelte": "^4.2.0",
"svelte-check": "^3.5.1",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite-plugin-inspect": "^0.7.38"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions packages/kitbook/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/.svelte-kit*
/dist
/.svelte-kit
dist
36 changes: 36 additions & 0 deletions packages/kitbook/kitbook.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { defineConfig } from "./src/lib/defineConfig";

export default defineConfig({
title: 'Kitbook',
description: 'Svelte Component Documentation and Prototyping Workbench built using SvelteKit',
viewports: [
{
name: 'Mobile',
width: 320,
height: 568,
},
{
name: 'Desktop',
width: 1024,
height: 768,
},
{
name: 'Tablet',
width: 768,
height: 1024,
},
],
// languages: [
// {
// name: 'English',
// code: 'en',
// },
// {
// name: 'Spanish',
// code: 'es',
// },
// ],
githubURL: 'https://github.com/jacob-8/kitbook/tree/main/packages/kitbook',
expandTree: true,
isKitbookItself: true,
});
47 changes: 27 additions & 20 deletions packages/kitbook/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "kitbook",
"version": "1.0.0-alpha.37",
"version": "1.0.0-alpha.40",
"description": "Svelte Component Documentation and Prototyping Workbench built using SvelteKit",
"scripts": {
"dev": "vite dev --mode kitbook",
"build": "vite build --mode kitbook",
"dev": "vite dev",
"build": "vite build",
"build:ci": "cd ../.. && pnpm build:deps && cd packages/kitbook && pnpm build",
"preview": "vite preview --mode kitbook",
"preview": "vite preview",
"sync": "svelte-kit sync",
"package": "svelte-kit sync && svelte-package && publint",
"package:watch": "svelte-kit sync && svelte-package --watch",
Expand All @@ -19,8 +19,7 @@
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist",
".gitignore"
"dist"
],
"exports": {
".": {
Expand All @@ -32,6 +31,11 @@
"types": "./dist/plugins/vite.d.ts",
"svelte": "./dist/plugins/vite.js",
"default": "./dist/plugins/vite.js"
},
"./defineConfig": {
"types": "./dist/defineConfig.d.ts",
"svelte": "./dist/defineConfig.js",
"default": "./dist/defineConfig.js"
}
},
"typesVersions": {
Expand All @@ -43,29 +47,32 @@
},
"dependencies": {
"@kitbook/mdsvex-shiki-twoslash": "0.0.4",
"@kitbook/vite-plugin-kitbook": "0.0.12",
"@kitbook/vite-plugin-kitbook": "0.0.14",
"svelte-pieces": "2.0.0-next.1",
"svelte2tsx": "^0.6.16"
"svelte2tsx": "^0.6.21"
},
"peerDependencies": {
"@playwright/test": "^1.37.1",
"@sveltejs/kit": "^1.13.0",
"svelte": "^3.55.0 || ^4.0.0"
},
"devDependencies": {
"@iconify/json": "^2.2.83",
"@iconify/json": "^2.2.113",
"@playwright/test": "^1.37.1",
"@sveltejs/adapter-auto": "2.1.0",
"@sveltejs/kit": "^1.20.5",
"@sveltejs/package": "^2.1.0",
"@unocss/svelte-scoped": "^0.53.4",
"@sveltejs/kit": "^1.24.1",
"@sveltejs/package": "^2.2.2",
"@unocss/svelte-scoped": "^0.55.7",
"mdsvex": "^0.11.0",
"prettier": "^2.8.8",
"publint": "^0.1.12",
"svelte": "^4.0.0",
"svelte-check": "^3.4.4",
"tslib": "^2.5.3",
"typescript": "~5.1.5",
"unocss": "^0.53.4",
"vite": "^4.3.9",
"vitest": "^0.32.2"
"publint": "^0.2.2",
"svelte": "^4.2.0",
"svelte-check": "^3.5.1",
"tslib": "^2.6.2",
"typescript": "~5.2.2",
"unocss": "^0.55.7",
"vite": "^4.4.9",
"vitest": "^0.34.4"
},
"repository": {
"type": "git",
Expand Down
18 changes: 0 additions & 18 deletions packages/kitbook/src/.kitbook/WrapRootLayout.svelte

This file was deleted.

3 changes: 0 additions & 3 deletions packages/kitbook/src/.kitbook/init.ts

This file was deleted.

17 changes: 11 additions & 6 deletions packages/kitbook/src/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ declare namespace App {
// interface Platform {}
}

// Syntax: https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-using-an-attributeevent-on-a-dom-element-and-it-throws-a-type-error
declare namespace svelteHTML {
// https://github.com/sveltejs/language-tools >> docs/preprocessors/typescript.md
interface HTMLAttributes<T> {
'on:updatewidth'?: (event: { detail: number }) => any;
'on:updateheight'?: (event: { detail: number }) => any;
"on:stopdragging"?: (event: boolean) => any;
"on:startdragging"?: (event: boolean) => any;
'on:updatewidth'?: (event: { detail: DragValues }) => any;
'on:updateheight'?: (event: { detail: DragValues }) => any;
'on:stopdragging'?: (event: boolean) => any;
'on:startdragging'?: (event: boolean) => any;
}
}
}

interface DragValues {
pixels: number,
percentage?: number,
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<link rel="icon" href="%sveltekit.assets%/icons/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="%sveltekit.assets%/styles/tw-reset.css">
<link rel="stylesheet" href="%sveltekit.assets%/styles/tw-prose.css">
%sveltekit.head%
</head>

Expand Down
41 changes: 30 additions & 11 deletions packages/kitbook/src/docs/1-get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,52 @@
- Install the `kitbook` package: `npm i -D kitbook@alpha` or `pnpm add -D kitbook@alpha`

- Add the `kitbook()` Vite plugin *before* your `sveltekit()` plugin:
```js title="vite.config.js" {2,6}
```js title="vite.config.js" {3,7}
import { defineConfig } from 'vite'
import { sveltekit } from '@sveltejs/kit/vite';
import { kitbook } from 'kitbook/plugins/vite';

const config = {
export default defineConfig({
plugins: [
kitbook(),
sveltekit(),
],
});
```

- Add the necessary [MDSvex](https://mdsvex.pngwn.io/) imports and configuration into your `svelte.config.js`:
```js title="svelte.config.js" {2,5,7}
import { vitePreprocess } from '@sveltejs/kit/vite';
import { mdsvex, MDSVEX_EXTENSIONS, KITBOOK_MDSVEX_CONFIG } from 'kitbook/plugins/vite';

const config = {
extensions: ['.svelte', ...MDSVEX_EXTENSIONS],
preprocess: [
mdsvex(KITBOOK_MDSVEX_CONFIG),
vitePreprocess(),
],
// ...
};

export default config;
```

- Add these scripts to your `package.json`:
```json
"kitbook": "vite dev --mode kitbook",
"kitbook:build": "svelte-kit sync && vite build --mode kitbook",
"kitbook:preview": "vite preview --mode kitbook",
- Place your app inside of a [(group)](https://kit.svelte.dev/docs/advanced-routing#advanced-layouts-group) folder named anything and add a `kitbook` folder to `src/routes`:
```txt {2,6}
src/routes/
│ (app)/
│ ├ dashboard/
│ ├ item/
│ └ +layout.svelte <-- initialize app only items, like db connections (refers to all layout files like +layout.ts)
│ kitbook/
└ +layout.svelte <-- initialize everything both your app and Kitbook need, like i18n
```

- Run `npm kitbook` or `pnpm kitbook`
- Run your dev server as normal (`npm run dev`, `pnpm dev`, etc...)

- Kitbook will quickly [[0-understand-kitbook-initialization|initialize]], and then you will want to **add an asterisk** to `/.svelte-kit` in your `.gitignore` file to modify it to `/.svelte-kit*` so the `/.svelte-kit-kitbook` folder isn't committed.
- Kitbook will automatically copy its routing files to `src/routes/kitbook`. Please edit the settings found in `src/routes/kitbook/+layout.svelte` for your app, but don't touch the other files as they will be overridden in future updates as needed.

At this point you can open Kitbook and see all your Svelte components, *including `+page.svelte` and `+layout.svelte` files as they are also just plain Svelte components with a very important `data` prop*.
At this point you can navigate to the `/kitbook` route and see all your Svelte components, *including `+page.svelte` and `+layout.svelte` files as they are also just plain Svelte components with a very important `data` prop*.

Next you could...

Expand All @@ -40,7 +60,6 @@ Next you could...

[//begin]: # "Autogenerated link references for markdown compatibility"
[4-roadmap]: 9-maintainer-notes/4-roadmap.md "Roadmap"
[0-understand-kitbook-initialization|initialize]: 3-customizations/0-understand-kitbook-initialization.md "Understand Kitbook's Initialization"
[2-write-documentation]: 2-write-documentation.md "Write Documentation"
[3-add-stories]: 3-add-stories.md "Add Stories"
[4-add-component-variants]: 4-add-component-variants.md "Add Component Variants"
Expand Down
3 changes: 2 additions & 1 deletion packages/kitbook/src/docs/2-variants/DefaultSlot.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Pass a Default Slot

It would be great to support dynamic slots for variants, but that may be crazy until Svelte officially supports that. However, we can support an optional default slot of html or a component as seen in the variants below.
It would be great to support dynamic slots for variants, but it would be error-prone until Svelte officially supports that. However, we can support an optional default slot of a string (you can pass html) or a component as seen in the variants below.

Possible dynamic slot options to research further:
- https://github.com/sveltejs/svelte/issues/2588
- https://github.com/sveltejs/svelte/pull/4296
- Playwright does them like this: https://github.com/microsoft/playwright/blob/d92fe16b76272afb19e7af5a2496f7efce45441d/packages/playwright-ct-svelte/registerSource.mjs#L82
24 changes: 9 additions & 15 deletions packages/kitbook/src/docs/2-variants/DefaultSlot.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,20 @@ import PassIntoDefaultSlot from './PassIntoDefaultSlot.svelte';
export const variants: Variants<Component> = [
{
name: 'Text',
slots: [
{
content: 'Just a bit of plain text.',
}
]
slots: {
default: 'Just a bit of plain text.',
}
},
{
name: 'HTML',
slots: [
{
content: 'Try some <i>italics</i>',
}
]
slots: {
default: 'Try some <i>italics</i>',
}
},
{
name: 'Component',
slots: [
{
content: PassIntoDefaultSlot,
}
]
slots: {
default: PassIntoDefaultSlot,
}
}
]
Loading

3 comments on commit 0014458

@vercel
Copy link

@vercel vercel bot commented on 0014458 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kitbook-template – ./packages/template

kitbook-template-polylingual.vercel.app
kitbook-template-git-main-polylingual.vercel.app
kitbook-template.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0014458 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-pieces – ./packages/svelte-pieces

svelte-pieces-polylingual.vercel.app
svelte-pieces.vercel.app
svelte-pieces-git-main-polylingual.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 0014458 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kitbook – ./packages/kitbook

kitbook-polylingual.vercel.app
kitbook.vercel.app
kitbook-git-main-polylingual.vercel.app

Please sign in to comment.