Skip to content

Commit

Permalink
refactor: reorganize code files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjavi committed Aug 30, 2023
1 parent 6a07d1d commit dd6c055
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 68 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
'test',
],
],
'scope-empty': [2, 'never'],
// 'scope-empty': [2, 'never'],
'scope-enum': [
2,
'always',
Expand Down
4 changes: 3 additions & 1 deletion packages/storylite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
},
"dependencies": {
"@r1stack/core": "^0.4.4",
"lucide-react": "^0.272.0"
"immer": "^10.0.2",
"lucide-react": "^0.272.0",
"zustand": "^4.4.1"
},
"devDependencies": {
"@r1stack/coding-style": "^0.4.4",
Expand Down
14 changes: 9 additions & 5 deletions packages/storylite/src/app/context/StoriesDataContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,25 @@ import {
StoryMeta,
StoryModulesMap,
} from '../..'
import { defaultConfig } from '../defaultConfig'
import {
getDefaultToolbarAddons,
getToolbarAddonsAsParameters,
resolveToolbarAddons,
} from '../getToolbarAddons'
} from '../../components/toolbar/getToolbarAddons'
import {
CrossDocumentMessage,
CrossDocumentMessageSource,
CrossDocumentMessageType,
registerWindowMessageListener,
sendWindowMessage,
} from '../messaging'
import { useParams, useSearchParamsMap } from '../router/router.state'
import { getLocalStorageItem, setLocalStorageItem } from './kvStorage'
} from '../../services/messenger'
import { useParams, useSearchParamsMap } from '../../services/router/router.state'
import { getLocalStorageItem, setLocalStorageItem } from '../../services/storage/localStorage'

export const defaultConfig: SLAppComponentProps = {
title: <> ⚡️ StoryLite</>,
defaultStory: 'index',
}

export type StoryLiteStateContextType = {
config?: SLAppComponentProps
Expand Down
6 changes: 0 additions & 6 deletions packages/storylite/src/app/defaultConfig.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/storylite/src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from 'react'

import { createStoryLiteRouter } from '../services/router/router.factory'
import { RouterProvider } from '../services/router/router.state'
import { SLAppComponentProps, StoryModulesMap } from '../types'
import { StoryLiteStateProvider } from './context/StoriesDataContext'
import { createStoryLiteRouter } from './router/router.factory'
import { RouterProvider } from './router/router.state'

// const router = createStoryLiteRouter()
const router = createStoryLiteRouter()
Expand Down
2 changes: 0 additions & 2 deletions packages/storylite/src/app/messaging/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/storylite/src/components/Story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { cn } from '@r1stack/core'

import { useStoryLiteStories } from '@/app/context/StoriesDataContext'
import { useSearchParamsMap } from '@/app/router/router.state'
import { useSearchParamsMap } from '@/services/router/router.state'
import { StoryComponent, StoryMeta, StoryModule } from '@/types'

export function Story({ story, exportName }: { story: string; exportName?: string }): JSX.Element {
Expand Down
2 changes: 1 addition & 1 deletion packages/storylite/src/components/canvas/CanvasIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HTMLProps } from 'react'
import { cn } from '@r1stack/core'

import { useStoryLiteConfig, useStoryLiteIframe } from '@/app/context/StoriesDataContext'
import { getStoryUrl } from '@/app/router/router.utils'
import { getStoryUrl } from '@/services/router/router.utils'

const allowList = [
'autoplay',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HTMLProps } from 'react'
import { cn } from '@r1stack/core'

import { useSearchParamsMap } from '@/app/router/router.state'
import { useSearchParamsMap } from '@/services/router/router.state'

import { Story } from '../Story'

Expand Down
2 changes: 1 addition & 1 deletion packages/storylite/src/components/layouts/IframeLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cn } from '@r1stack/core'

import { useStoryLiteConfig, useStoryLiteParameters } from '@/app/context/StoriesDataContext'
import { useDetectTheme } from '@/app/hooks/useDetectTheme'
import { parametersToDataProps } from '@/app/parameters/parametersToDataProps'
import { useDetectTheme } from '@/hooks/useDetectTheme'

export default function CanvasIframeLayout({ children, ...props }: any) {
const { standalone } = props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useStoryLiteParameters } from '@/app/context/StoriesDataContext'
import { useDetectTheme } from '@/app/hooks/useDetectTheme'
import { parametersToDataProps } from '@/app/parameters/parametersToDataProps'
import { useDetectTheme } from '@/hooks/useDetectTheme'

import { Sidebar } from '../sidebar/Sidebar'
import { SidebarTitle } from '../sidebar/SidebarTitle'
Expand Down
6 changes: 3 additions & 3 deletions packages/storylite/src/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import React, { useState } from 'react'
import { BookmarkIcon, MinusSquareIcon, PlusSquareIcon } from 'lucide-react'

import { useStoryLiteStories } from '@/app/context/StoriesDataContext'
import { Link } from '@/app/router'
import { useParams } from '@/app/router/router.state'
import { getStoryUrl } from '@/app/router/router.utils'
import { Link } from '@/services/router'
import { useParams } from '@/services/router/router.state'
import { getStoryUrl } from '@/services/router/router.utils'
import { StoryMeta, StoryModule, StoryModulesMapValue } from '@/types'

type SidebarProps = {
Expand Down
2 changes: 1 addition & 1 deletion packages/storylite/src/components/sidebar/SidebarTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useStoryLiteConfig } from '@/app/context/StoriesDataContext'
import { Link } from '@/app/router/router.component'
import { Link } from '@/services/router/router.component'

export function SidebarTitle() {
const config = useStoryLiteConfig()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
SLCoreAddon,
SLParameters,
SLUserDefinedAddons,
} from '..'
import { getStoryUrl } from './router/router.utils'
import { isNotEmpty, isTruthy } from './utils'
} from '../..'
import { getStoryUrl } from '../../services/router/router.utils'
import { isNotEmpty, isTruthy } from '../../utility'

export function getToolbarAddonsAsParameters(addons: SLAddonsMap): SLParameters {
const parameters: SLParameters = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'

import { SLColorScheme } from '@/types'

import { useStoryLiteConfig, useStoryLiteParameters } from '../context/StoriesDataContext'
import { useStoryLiteConfig, useStoryLiteParameters } from '../app/context/StoriesDataContext'

export function useDetectTheme(): string {
const userConfig = useStoryLiteConfig()
Expand Down
2 changes: 1 addition & 1 deletion packages/storylite/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './app'
export * from './app/context/StoriesDataContext'
export * from './app/renderStoryLiteApp'
export * from './app/router'
export * from './services/router'
export * from './types'
2 changes: 2 additions & 0 deletions packages/storylite/src/services/messenger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './windowMessaging'
export * from './windowMessaging.types'
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { CrossDocumentMessage, CrossDocumentMessageSource, WindowMessageOrigin } from './types'
import {
CrossDocumentMessage,
CrossDocumentMessageSource,
WindowMessageOrigin,
} from './windowMessaging.types'

export const sendWindowMessageToRoot = (message: CrossDocumentMessage) => {
sendWindowMessage(message, CrossDocumentMessageSource.Iframe, window.parent)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import all pages manually (we are not in the Vite context here; cannot use import.meta.glob)
import TopFrameLayout from '../../components/layouts/TopFrameLayout'
import * as Error404 from '../../pages/404'
// import all pages manually (we are not in the Vite context here; cannot use import.meta.glob)
import * as IndexPage from '../../pages/index'
import * as SandboxDashboardPage from '../../pages/preview/dashboard'
import * as SandboxStoryIndex from '../../pages/preview/stories/[story]'
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion packages/vite-plugin/public/vite.svg

This file was deleted.

43 changes: 39 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dd6c055

Please sign in to comment.