@particle-academy/fancy-code 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import * as react from 'react';
2
2
  import { RefObject, ReactNode } from 'react';
3
+ import { InputTagProps, InputTagTriggers, InputTagAdapter } from '@particle-academy/react-fancy';
3
4
 
4
5
  interface ThemeColors {
5
6
  background: string;
@@ -114,6 +115,13 @@ interface CodeEditorContextValue {
114
115
  };
115
116
  /** Length of the current selection (0 if none) */
116
117
  selectionLength: number;
118
+ /**
119
+ * Ref to the underlying `<textarea>` element. Exposed so external
120
+ * widgets — e.g. `<InputTag>`'s `textareaAdapter` — can attach to
121
+ * the same input the editor renders into. Will be `null` before
122
+ * the editor has mounted.
123
+ */
124
+ textareaRef: RefObject<HTMLTextAreaElement | null>;
117
125
  /** Placeholder text */
118
126
  placeholder?: string;
119
127
  /** @internal */
@@ -135,27 +143,27 @@ interface CodeEditorStatusBarProps {
135
143
  className?: string;
136
144
  }
137
145
 
138
- declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react_jsx_runtime.JSX.Element | null;
146
+ declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react.JSX.Element | null;
139
147
  declare namespace CodeEditorPanel {
140
148
  var displayName: string;
141
149
  }
142
150
 
143
- declare function CodeEditorToolbar({ children, className }: CodeEditorToolbarProps): react_jsx_runtime.JSX.Element;
151
+ declare function CodeEditorToolbar({ children, className }: CodeEditorToolbarProps): react.JSX.Element;
144
152
  declare namespace CodeEditorToolbar {
145
153
  var displayName: string;
146
154
  }
147
155
 
148
- declare function CodeEditorToolbarSeparator(): react_jsx_runtime.JSX.Element;
156
+ declare function CodeEditorToolbarSeparator(): react.JSX.Element;
149
157
  declare namespace CodeEditorToolbarSeparator {
150
158
  var displayName: string;
151
159
  }
152
160
 
153
- declare function CodeEditorStatusBar({ children, className }: CodeEditorStatusBarProps): react_jsx_runtime.JSX.Element;
161
+ declare function CodeEditorStatusBar({ children, className }: CodeEditorStatusBarProps): react.JSX.Element;
154
162
  declare namespace CodeEditorStatusBar {
155
163
  var displayName: string;
156
164
  }
157
165
 
158
- declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight, }: CodeEditorProps): react_jsx_runtime.JSX.Element;
166
+ declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight, }: CodeEditorProps): react.JSX.Element;
159
167
  declare namespace CodeEditorRoot {
160
168
  var displayName: string;
161
169
  }
@@ -194,4 +202,45 @@ declare function registerTheme(theme: ThemeDefinition): void;
194
202
  declare function getTheme(name: string): ThemeDefinition | undefined;
195
203
  declare function getRegisteredThemes(): string[];
196
204
 
197
- export { CodeEditor, type CodeEditorContextValue, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeColors, type ThemeDefinition, type Token, type TokenType, type Tokenizer, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor };
205
+ /**
206
+ * Glue between `@particle-academy/react-fancy`'s `<InputTag>` and the
207
+ * `<CodeEditor>` from this package. `<CodeEditor>` renders a real DOM
208
+ * `<textarea>` under its overlay, so the existing `textareaAdapter`
209
+ * just works — this module hands it the right ref via the editor
210
+ * context.
211
+ *
212
+ * <CodeEditor value={code} onChange={setCode} language="markdown">
213
+ * <CodeEditor.Toolbar />
214
+ * <CodeEditor.Panel />
215
+ * <CodeEditorInputTag
216
+ * triggers={{
217
+ * "/": { items: commands, insert: (c) => `${c.name} ` },
218
+ * "@": { items: mentions, insert: (m) => `@${m.name} ` },
219
+ * }}
220
+ * />
221
+ * </CodeEditor>
222
+ *
223
+ * Must be rendered as a descendant of `<CodeEditor>` (it reads the
224
+ * editor's context). For ad-hoc wiring outside the component tree,
225
+ * pull the textarea ref off the context and call `textareaAdapter`
226
+ * yourself.
227
+ */
228
+ /**
229
+ * Hook form — returns an `InputTagAdapter` bound to the surrounding
230
+ * `<CodeEditor>`. Useful when you want to compose your own picker UI
231
+ * around the same adapter.
232
+ */
233
+ declare function useCodeEditorInputTagAdapter(): InputTagAdapter;
234
+ interface CodeEditorInputTagProps extends Omit<InputTagProps, "adapter"> {
235
+ triggers: InputTagTriggers;
236
+ }
237
+ /**
238
+ * Convenience wrapper — renders `<InputTag>` already wired to the
239
+ * surrounding `<CodeEditor>`'s textarea. Equivalent to:
240
+ *
241
+ * const adapter = useCodeEditorInputTagAdapter();
242
+ * return <InputTag adapter={adapter} {...rest} />;
243
+ */
244
+ declare function CodeEditorInputTag(props: CodeEditorInputTagProps): react.JSX.Element;
245
+
246
+ export { CodeEditor, type CodeEditorContextValue, CodeEditorInputTag, type CodeEditorInputTagProps, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeColors, type ThemeDefinition, type Token, type TokenType, type Tokenizer, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor, useCodeEditorInputTagAdapter };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ import * as react from 'react';
2
2
  import { RefObject, ReactNode } from 'react';
3
+ import { InputTagProps, InputTagTriggers, InputTagAdapter } from '@particle-academy/react-fancy';
3
4
 
4
5
  interface ThemeColors {
5
6
  background: string;
@@ -114,6 +115,13 @@ interface CodeEditorContextValue {
114
115
  };
115
116
  /** Length of the current selection (0 if none) */
116
117
  selectionLength: number;
118
+ /**
119
+ * Ref to the underlying `<textarea>` element. Exposed so external
120
+ * widgets — e.g. `<InputTag>`'s `textareaAdapter` — can attach to
121
+ * the same input the editor renders into. Will be `null` before
122
+ * the editor has mounted.
123
+ */
124
+ textareaRef: RefObject<HTMLTextAreaElement | null>;
117
125
  /** Placeholder text */
118
126
  placeholder?: string;
119
127
  /** @internal */
@@ -135,27 +143,27 @@ interface CodeEditorStatusBarProps {
135
143
  className?: string;
136
144
  }
137
145
 
138
- declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react_jsx_runtime.JSX.Element | null;
146
+ declare function CodeEditorPanel({ className }: CodeEditorPanelProps): react.JSX.Element | null;
139
147
  declare namespace CodeEditorPanel {
140
148
  var displayName: string;
141
149
  }
142
150
 
143
- declare function CodeEditorToolbar({ children, className }: CodeEditorToolbarProps): react_jsx_runtime.JSX.Element;
151
+ declare function CodeEditorToolbar({ children, className }: CodeEditorToolbarProps): react.JSX.Element;
144
152
  declare namespace CodeEditorToolbar {
145
153
  var displayName: string;
146
154
  }
147
155
 
148
- declare function CodeEditorToolbarSeparator(): react_jsx_runtime.JSX.Element;
156
+ declare function CodeEditorToolbarSeparator(): react.JSX.Element;
149
157
  declare namespace CodeEditorToolbarSeparator {
150
158
  var displayName: string;
151
159
  }
152
160
 
153
- declare function CodeEditorStatusBar({ children, className }: CodeEditorStatusBarProps): react_jsx_runtime.JSX.Element;
161
+ declare function CodeEditorStatusBar({ children, className }: CodeEditorStatusBarProps): react.JSX.Element;
154
162
  declare namespace CodeEditorStatusBar {
155
163
  var displayName: string;
156
164
  }
157
165
 
158
- declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight, }: CodeEditorProps): react_jsx_runtime.JSX.Element;
166
+ declare function CodeEditorRoot({ children, className, value: valueProp, defaultValue, onChange, language: languageProp, onLanguageChange, theme, readOnly, lineNumbers: lineNumbersProp, wordWrap: wordWrapProp, tabSize: tabSizeProp, placeholder, minHeight, maxHeight, }: CodeEditorProps): react.JSX.Element;
159
167
  declare namespace CodeEditorRoot {
160
168
  var displayName: string;
161
169
  }
@@ -194,4 +202,45 @@ declare function registerTheme(theme: ThemeDefinition): void;
194
202
  declare function getTheme(name: string): ThemeDefinition | undefined;
195
203
  declare function getRegisteredThemes(): string[];
196
204
 
197
- export { CodeEditor, type CodeEditorContextValue, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeColors, type ThemeDefinition, type Token, type TokenType, type Tokenizer, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor };
205
+ /**
206
+ * Glue between `@particle-academy/react-fancy`'s `<InputTag>` and the
207
+ * `<CodeEditor>` from this package. `<CodeEditor>` renders a real DOM
208
+ * `<textarea>` under its overlay, so the existing `textareaAdapter`
209
+ * just works — this module hands it the right ref via the editor
210
+ * context.
211
+ *
212
+ * <CodeEditor value={code} onChange={setCode} language="markdown">
213
+ * <CodeEditor.Toolbar />
214
+ * <CodeEditor.Panel />
215
+ * <CodeEditorInputTag
216
+ * triggers={{
217
+ * "/": { items: commands, insert: (c) => `${c.name} ` },
218
+ * "@": { items: mentions, insert: (m) => `@${m.name} ` },
219
+ * }}
220
+ * />
221
+ * </CodeEditor>
222
+ *
223
+ * Must be rendered as a descendant of `<CodeEditor>` (it reads the
224
+ * editor's context). For ad-hoc wiring outside the component tree,
225
+ * pull the textarea ref off the context and call `textareaAdapter`
226
+ * yourself.
227
+ */
228
+ /**
229
+ * Hook form — returns an `InputTagAdapter` bound to the surrounding
230
+ * `<CodeEditor>`. Useful when you want to compose your own picker UI
231
+ * around the same adapter.
232
+ */
233
+ declare function useCodeEditorInputTagAdapter(): InputTagAdapter;
234
+ interface CodeEditorInputTagProps extends Omit<InputTagProps, "adapter"> {
235
+ triggers: InputTagTriggers;
236
+ }
237
+ /**
238
+ * Convenience wrapper — renders `<InputTag>` already wired to the
239
+ * surrounding `<CodeEditor>`'s textarea. Equivalent to:
240
+ *
241
+ * const adapter = useCodeEditorInputTagAdapter();
242
+ * return <InputTag adapter={adapter} {...rest} />;
243
+ */
244
+ declare function CodeEditorInputTag(props: CodeEditorInputTagProps): react.JSX.Element;
245
+
246
+ export { CodeEditor, type CodeEditorContextValue, CodeEditorInputTag, type CodeEditorInputTagProps, type CodeEditorPanelProps, type CodeEditorProps, type CodeEditorStatusBarProps, type CodeEditorToolbarProps, type LanguageDefinition, type ThemeColors, type ThemeDefinition, type Token, type TokenType, type Tokenizer, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor, useCodeEditorInputTagAdapter };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createContext, useState, useCallback, useRef, useMemo, useSyncExternalStore, useEffect, useContext } from 'react';
2
- import { cn, useControllableState } from '@particle-academy/react-fancy';
2
+ import { cn, useControllableState, textareaAdapter, InputTag } from '@particle-academy/react-fancy';
3
3
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
4
 
5
5
  // src/components/CodeEditor/CodeEditor.tsx
@@ -1576,6 +1576,7 @@ function CodeEditorRoot({
1576
1576
  },
1577
1577
  cursorPosition,
1578
1578
  selectionLength,
1579
+ textareaRef: engineReturn.textareaRef,
1579
1580
  placeholder,
1580
1581
  _engineReturn: engineReturn,
1581
1582
  _minHeight: minHeight,
@@ -1604,7 +1605,15 @@ var CodeEditor = Object.assign(CodeEditorRoot, {
1604
1605
  Panel: CodeEditorPanel,
1605
1606
  StatusBar: CodeEditorStatusBar
1606
1607
  });
1608
+ function useCodeEditorInputTagAdapter() {
1609
+ const ctx = useCodeEditor();
1610
+ return useMemo(() => textareaAdapter(ctx.textareaRef), [ctx.textareaRef]);
1611
+ }
1612
+ function CodeEditorInputTag(props) {
1613
+ const adapter = useCodeEditorInputTagAdapter();
1614
+ return /* @__PURE__ */ jsx(InputTag, { adapter, ...props });
1615
+ }
1607
1616
 
1608
- export { CodeEditor, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor };
1617
+ export { CodeEditor, CodeEditorInputTag, getLanguage, getRegisteredLanguages, getRegisteredThemes, getTheme, registerLanguage, registerTheme, useCodeEditor, useCodeEditorInputTagAdapter };
1609
1618
  //# sourceMappingURL=index.js.map
1610
1619
  //# sourceMappingURL=index.js.map