Logo React Mosaic

React Mosaic

Cộng đồngPhổ biến
nomcopter
react-mosaic

Build tiling window manager layouts in React with react-mosaic-component (v7) - resizable, drag-and-drop rearrangeable panels, splits and tab groups. Use when writing or changing code that imports react-mosaic-component, uses Mosaic / MosaicWindow / MosaicNode, or when asked for an IDE-like, dockable, resizable or tiled panel layout in React.

Tổng quan

Nhà phát hànhnomcopter
Kho mãreact-mosaic
Tên kỹ năngreact-mosaic
Sao
4.8K
Bản fork
242
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được nomcopter công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI React Mosaic trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/nomcopter/react-mosaic/tree/master/skills/react-mosaic
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nomcopter/react-mosaic.git /tmp/react-mosaic
mkdir -p .claude/skills
cp -r /tmp/react-mosaic/skills/react-mosaic .claude/skills/react-mosaic
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật React Mosaic trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp React Mosaic ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng React Mosaic với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

react-mosaic-component (v7)

A React tiling window manager (React 16-19, TypeScript). The layout is an immutable n-ary tree of panels. Full docs: https://nomcopter.github.io/react-mosaic/

v7 is not v6. Most examples online (and in older training data) use the v6 binary tree (first / second, splitPercentage, string paths like ['first']). That shape is legacy. Write v7 code as shown here.

Setup

bash
npm install react-mosaic-component
tsx
import 'react-mosaic-component/react-mosaic-component.css'; // required

<Mosaic> fills its parent, so the parent must have a real height (e.g. height: 100vh), otherwise nothing is visible.

Minimal example

tsx
import { Mosaic, MosaicWindow, type MosaicNode } from 'react-mosaic-component';
import 'react-mosaic-component/react-mosaic-component.css';

const initial: MosaicNode<string> = {
  type: 'split',
  direction: 'row', // 'row' = side by side, 'column' = stacked
  splitPercentages: [30, 70], // optional, sums to 100
  children: [
    'files',
    { type: 'split', direction: 'column', children: ['editor', 'terminal'] },
  ],
};

export function App() {
  return (
    <div style={{ height: '100vh' }}>
      <Mosaic<string>
        initialValue={initial}
        renderTile={(id, path) => (
          <MosaicWindow<string> path={path} title={id}>
            <Panel id={id} />
          </MosaicWindow>
        )}
      />
    </div>
  );
}

renderTile(key, path) is called for every leaf. Pass the path it gives you straight to MosaicWindow; never compute paths yourself.

The tree

ts
type MosaicKey = string | number; // a leaf is just its key
type MosaicNode<T> = MosaicSplitNode<T> | MosaicTabsNode<T> | T;

interface MosaicSplitNode<T> {
  type: 'split';
  direction: 'row' | 'column';
  children: MosaicNode<T>[]; // any number of children
  splitPercentages?: number[]; // one per child, sums to 100; omit for equal sizes
}

interface MosaicTabsNode<T> {
  type: 'tabs';
  tabs: T[]; // leaf keys only, tab groups don't nest
  activeTabIndex: number;
}
  • A bare key ('editor') is a valid whole tree: one full-size window.
  • null is an empty layout; zeroStateView is shown.
  • Keys must be unique in the tree. They are your IDs: map them to content in renderTile, don't put components or objects in the tree. Keep the tree JSON-serialisable so it can be persisted.
  • Paths are numeric index arrays: [] is the root, [1, 0] is the first child of the second child. For a tab group, the active tab's path is the group's path plus the tab index.
  • Narrow with isSplitNode(node) / isTabsNode(node); anything else is a leaf.

Controlled vs uncontrolled

Use either initialValue (Mosaic owns the state) or value + onChange (you own it). Never both. Go controlled whenever you persist the layout or change it from outside.

tsx
const [tree, setTree] = useState<MosaicNode<string> | null>(initial);

<Mosaic<string>
  value={tree}
  onChange={setTree} // every change, including each frame of a resize drag
  onRelease={(next) => save(next)} // once per finished interaction: persist here
  renderTile={renderTile}
/>;

Both callbacks get a second meta argument describing the change, e.g. { type: 'remove', path, node }, { type: 'resize', path, splitPercentages }, { type: 'drop', node, sourcePath, destinationPath, position?, tabIndex?, swap? }, { type: 'tab-add' | 'tab-remove' | 'tab-select', ... }. Paths in meta refer to the tree before the change. See MosaicChangeMeta.

Changing the tree

Never mutate a tree in place; the UI won't update. Two ways to change it:

Inside the mosaic (toolbar buttons, tile content), use the context actions:

tsx
import { useMosaic, useMosaicWindow } from 'react-mosaic-component';

function CloseButton({ path }: { path: MosaicPath }) {
  const { mosaicActions } = useMosaic<string>();
  return <button onClick={() => mosaicActions.remove(path)}>Close</button>;
}
// mosaicActions: remove(path), expand(path, pct?), replaceWith(path, node),
//   updateTree(updates), addTab(path), removeTab(path, index), getRoot()
// useMosaicWindow().mosaicWindowActions: split(), addTab(), replaceWithNew(),
//   getPath(), setAdditionalControlsOpen(open | 'toggle'), connectDragSource(el)

split(), addTab() and replaceWithNew() need the createNode prop (on Mosaic or MosaicWindow), which returns the new node (or a promise of one).

Outside the mosaic (controlled mode), compute a new tree and setTree it:

ts
import {
  updateTree,
  createRemoveUpdate,
  createExpandUpdate,
} from 'react-mosaic-component';

setTree((t) => (t ? updateTree(t, [createRemoveUpdate(t, [1, 0])]) : t));

Helpers (all pure, return new objects):

HelperUse
updateTree(tree, updates)apply MosaicUpdate[] ({ path, spec }, spec is an immutability-helper command)
createRemoveUpdate(tree, path)remove a node, collapsing its parent
createExpandUpdate(path, percentage)grow a node at every level up to the root
createSwapUpdates(tree, pathA, pathB)swap two nodes (returns an array)
createDragToUpdates(tree, source, dest, dropInfo)what a drag does, e.g. { type: 'split', position: 'left' } (returns an array)
getNodeAtPath(tree, path), getParentNode, getParentPathreads
getLeaves(tree)all leaf keys, e.g. to check if a panel is open
createBalancedTreeFromLeaves(keys, 'row')build a layout from a list of keys
convertLegacyToNary(tree)convert a stored v6 tree

To add a panel from outside, the simplest correct approach is to rebuild: createBalancedTreeFromLeaves([...getLeaves(tree), 'new']), or wrap the root: { type: 'split', direction: 'row', children: [tree, 'new'] }.

MosaicWindow

tsx
<MosaicWindow<string>
  path={path} // required, from renderTile
  title="Editor" // required
  toolbarControls={[<SplitButton key="s" />, <RemoveButton key="r" />]} // replaces default buttons
  createNode={() => nextId()}
  draggable // default true; false disables dragging by the title bar
  renderToolbar={(props, draggable) => <MyToolbar />} // optional: replace the whole title bar
>
  ...
</MosaicWindow>

Toolbar building blocks: ExpandButton, SplitButton, ReplaceButton, RemoveButton, Separator, DefaultToolbarButton, DEFAULT_CONTROLS_WITH_CREATION, DEFAULT_CONTROLS_WITHOUT_CREATION. Using MosaicWindow is optional: renderTile can return any element.

Tabs

Put a { type: 'tabs', tabs: ['a', 'b'], activeTabIndex: 0 } node anywhere a leaf can go. renderTile is called only for the active tab. Tab-related Mosaic props: canClose(tabKey, tabs, index, path) returning 'canClose' | 'cannotClose' | 'noClose', renderTabTitle, renderTabButton, renderTabToolbarControls (compose DefaultAddTabButton, TabSplitButton, TabRemoveButton), and renderTabToolbar for a fully custom tab bar.

Other Mosaic props

  • resize: 'DISABLED' or { minimumPaneSizePercentage?, minimumPaneSizePx?, renderSplitHandle?, preview? }. preview: true only moves the divider while dragging and resizes once on release.
  • dropBehavior: 'split' (default), 'swap', or 'split-and-swap'.
  • zeroStateView: element shown when the tree is null.
  • className: default 'mosaic-blueprint-theme'. Blueprint is optional; for Blueprint dark mode use 'mosaic-blueprint-theme bp5-dark' and load Blueprint's CSS. With your own theme, pass your own class name.
  • mosaicId: set a fixed one when external drag sources must drop into the layout.

Drag and drop

Mosaic sets up react-dnd itself (HTML5 + touch). If the app already has a DndProvider, render MosaicWithoutDragDropContext (same props) inside it instead of nesting a second provider, and share one copy of react-dnd 16. External drops use drag type MosaicDragType.WINDOW; drop targets outside the layout can return { remove: true } to take the dragged window out. Docs: https://nomcopter.github.io/react-mosaic/docs/guides/drag-and-drop

Common mistakes

  • v6 shapes: { direction, first, second }, splitPercentage, ['first'] paths. Use type: 'split', children, splitPercentages, numeric paths.
  • Forgetting the CSS import, or a parent with no height.
  • Passing both value and initialValue, or value without onChange.
  • Mutating the tree (tree.children.push(...)) instead of returning a new one.
  • Saving on every onChange during a resize drag; persist in onRelease.
  • splitPercentages whose length differs from children or doesn't sum to 100.
  • Duplicate keys in the tree, or nesting a tabs node inside tabs.
  • Hand-writing paths instead of using the path from renderTile / useMosaicWindow().mosaicWindowActions.getPath().

The TypeScript declarations in this package (index.d.ts) are the source of truth for every signature.

Câu hỏi thường gặp

Kỹ năng AI React Mosaic làm được gì?

Build tiling window manager layouts in React with react-mosaic-component (v7) - resizable, drag-and-drop rearrangeable panels, splits and tab groups. Use when writing or changing code that imports react-mosaic-component, uses Mosaic / MosaicWindow / MosaicNode, or when asked for an IDE-like, dockable, resizable or tiled panel layout in React.

Vì sao nên dùng React Mosaic trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. React Mosaic là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài React Mosaic trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/nomcopter/react-mosaic/tree/master/skills/react-mosaic. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng React Mosaic?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng React Mosaic với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng React Mosaic với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI React Mosaic có miễn phí không?

Kỹ năng này được nomcopter phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇