Skip to content

3분 빠른 시작 ​

라이브 예제

1. 설치 ​

공식 npm 레지스트리에서 reddokia를 설치합니다.

bash
npm install reddokia

번들러(npm install) 없이 순수 HTML <script type="module">에서 CDN 또는 GitHub Pages 주소로 즉시 불러와 사용할 수도 있습니다:

html
<script type="module">
  // jsDelivr CDN (npm)
  import { RedDokia, RedDokiaIcons } from 'https://cdn.jsdelivr.net/npm/reddokia/dist/reddokia.js';

  // 또는 GitHub Pages 직접 로드
  // import { RedDokia, RedDokiaIcons } from 'https://redcamel.github.io/RedDokia/dist/reddokia.js';
</script>

스타일 자동 주입

기본 설정에서는 RedDokia가 마운트 시 필요한 CSS를 자동으로 <head>에 주입합니다. Strict CSP 환경에서 정적 CSS로 번들링하려면 Strict CSP & 프로덕션 가이드를 참고하세요.

2. 공용 레이아웃 스키마 정의 (layoutSchema.ts) ​

layoutSchema는 React · Vue · Svelte · Vanilla에서 100% 동일하게 사용합니다. type을 생략하면 기본값 'row'(좌우 분할)가 적용되며, string[] 배열만으로 탭 그룹을 간결하게 선언할 수 있습니다.

ts
import type { RedDokiaLayoutSchema } from 'reddokia';

export const layoutSchema: RedDokiaLayoutSchema = {
  contents: {
    children: [
      ['explorer'],
      ['editor', 'preview'],
    ],
  },
};

3. 프레임워크별 마운트 ​

각 프레임워크의 표준 컴포넌트(.tsx, .vue, .svelte) 또는 마운트 함수를 views에 그대로 등록합니다. title을 생략하면 id('explorer')를 기반으로 탭 제목('Explorer')이 자동 포맷됩니다.

tsx
import { RedDokia, RedDokiaIcons, type RedDokiaViewSchema } from 'reddokia/react';
import { layoutSchema } from './layoutSchema';
import ExplorerPanel from './ExplorerPanel';
import EditorPanel from './EditorPanel';
import PreviewPanel from './PreviewPanel';

const views: RedDokiaViewSchema[] = [
  { id: 'explorer', icon: RedDokiaIcons.Layout, component: ExplorerPanel },
  { id: 'editor', title: 'App.tsx', icon: RedDokiaIcons.Layers, component: EditorPanel },
  { id: 'preview', title: 'Preview', icon: RedDokiaIcons.Terminal, component: PreviewPanel },
];

export default function App() {
  return (
    <div style={{ width: '100vw', height: '100vh' }}>
      <RedDokia views={views} layout={layoutSchema} />
    </div>
  );
}
vue
<script setup lang="ts">
import { RedDokia, RedDokiaIcons, type RedDokiaViewSchema } from 'reddokia/vue';
import { layoutSchema } from './layoutSchema';
import ExplorerPanel from './ExplorerPanel.vue';
import EditorPanel from './EditorPanel.vue';
import PreviewPanel from './PreviewPanel.vue';

const views: RedDokiaViewSchema[] = [
  { id: 'explorer', icon: RedDokiaIcons.Layout, component: ExplorerPanel },
  { id: 'editor', title: 'App.tsx', icon: RedDokiaIcons.Layers, component: EditorPanel },
  { id: 'preview', title: 'Preview', icon: RedDokiaIcons.Terminal, component: PreviewPanel },
];
</script>

<template>
  <div style="width: 100vw; height: 100vh">
    <RedDokia :views="views" :layout="layoutSchema" />
  </div>
</template>
svelte
<script lang="ts">
  import { RedDokia, RedDokiaIcons, type RedDokiaViewSchema } from 'reddokia/svelte';
  import { layoutSchema } from './layoutSchema';
  import ExplorerPanel from './ExplorerPanel.svelte';
  import EditorPanel from './EditorPanel.svelte';
  import PreviewPanel from './PreviewPanel.svelte';

  const views: RedDokiaViewSchema[] = [
    { id: 'explorer', icon: RedDokiaIcons.Layout, component: ExplorerPanel },
    { id: 'editor', title: 'App.tsx', icon: RedDokiaIcons.Layers, component: EditorPanel },
    { id: 'preview', title: 'Preview', icon: RedDokiaIcons.Terminal, component: PreviewPanel },
  ];
</script>

<div style="width: 100vw; height: 100vh">
  <RedDokia {views} layout={layoutSchema} />
</div>
ts
import { RedDokia, RedDokiaIcons, type RedDokiaViewSchema } from 'reddokia';
import { layoutSchema } from './layoutSchema';
import ExplorerPanel from './ExplorerPanel';
import EditorPanel from './EditorPanel';
import PreviewPanel from './PreviewPanel';

const views: RedDokiaViewSchema[] = [
  { id: 'explorer', icon: RedDokiaIcons.Layout, component: ExplorerPanel },
  { id: 'editor', title: 'App.tsx', icon: RedDokiaIcons.Layers, component: EditorPanel },
  { id: 'preview', title: 'Preview', icon: RedDokiaIcons.Terminal, component: PreviewPanel },
];

const dock = new RedDokia(document.getElementById('app')!, {
  views,
  layout: layoutSchema,
});

호스트 컨테이너 높이 필수

RedDokia는 부모 컨테이너의 100% × 100%를 채웁니다. 부모 요소에 height: 100vh 또는 flex: 1; min-height: 0 등 명시적 높이가 지정되어 있어야 합니다.

4. 패널 컴포넌트 작성 (EditorPanel) ​

모든 패널은 현재 크기(width, height), 활성 여부(active), controller가 담긴 RedDokiaViewRenderProps를 자동으로 전달받습니다.

tsx
import type { RedDokiaViewRenderProps } from 'reddokia/react';

export default function EditorPanel({ width, height, controller }: RedDokiaViewRenderProps) {
  return (
    <div style={{ padding: 16 }}>
      <h3>Editor ({Math.round(width)} × {Math.round(height)} px)</h3>
      <button onClick={() => controller.floatView('editor')}>플로팅 분리</button>
    </div>
  );
}
vue
<script setup lang="ts">
import type { RedDokiaViewRenderProps } from 'reddokia/vue';

const props = defineProps<RedDokiaViewRenderProps>();
</script>

<template>
  <div style="padding: 16px">
    <h3>Editor ({{ Math.round(props.width) }} × {{ Math.round(props.height) }} px)</h3>
    <button @click="props.controller.floatView('editor')">플로팅 분리</button>
  </div>
</template>
svelte
<script lang="ts">
  import type { RedDokiaViewRenderProps } from 'reddokia/svelte';

  let { width, height, controller }: RedDokiaViewRenderProps = $props();
</script>

<div style="padding: 16px">
  <h3>Editor ({Math.round(width)} × {Math.round(height)} px)</h3>
  <button onclick={() => controller.floatView('editor')}>플로팅 분리</button>
</div>
ts
import type { RedDokiaViewMountHandler } from 'reddokia';

const EditorPanel: RedDokiaViewMountHandler = (el, { width, height }) => {
  el.textContent = `Editor (${Math.round(width)} × ${Math.round(height)} px)`;
  return {
    update: ({ width: w, height: h }) => {
      el.textContent = `Editor (${Math.round(w)} × ${Math.round(h)} px)`;
    },
  };
};

export default EditorPanel;

다음 단계 ​