@collabchron/notiq 0.3.0 → 1.0.0
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/LICENSE +21 -0
- package/README.md +230 -39
- package/dist/CodeActionMenuPlugin-EINOY4U4.mjs +15 -0
- package/dist/DynamicBlockComponent-NRQJ4WW4.mjs +161 -0
- package/dist/EquationComponent-CB6DFIHV.mjs +154 -0
- package/dist/ExcalidrawComponent-XW6646OH.mjs +528 -0
- package/dist/ExcalidrawPlugin-ZFHT62IF.mjs +14 -0
- package/dist/ExportPlugin-V2RLM63S.mjs +11 -0
- package/dist/FloatingLinkEditorPlugin-TRTCMSP4.mjs +12 -0
- package/dist/FloatingTextFormatToolbarPlugin-F2GY6LMI.mjs +30 -0
- package/dist/HintComponet-BRL6EAMS.mjs +217 -0
- package/dist/InlineImageComponent-UWIUWBHI.mjs +453 -0
- package/dist/MobileToolbar-BOOZAMQE.mjs +268 -0
- package/dist/SlashCommand-GMT5JI33.mjs +28 -0
- package/dist/StoryBuilderComponent-JGDBM5JU.mjs +562 -0
- package/{src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx → dist/TableCellActionMenuPlugin-PGK2K3VG.mjs} +667 -759
- package/{src/components/editor/plugins/TableHoverActionsPlugin/index.tsx → dist/TableHoverActionsPlugin-GJVE6VRW.mjs} +258 -314
- package/dist/TemplatePlugin-ZD3QEVTI.mjs +9 -0
- package/dist/ToolbarPlugin-7TOZRD2R.mjs +1547 -0
- package/dist/babel-JZ2EV6AX.mjs +7233 -0
- package/dist/background-color-XZTYLGO2.mjs +362 -0
- package/dist/block-format-YJCV2DIY.mjs +15 -0
- package/dist/chunk-2FNEAMSP.mjs +127 -0
- package/dist/chunk-3CPBODXA.mjs +84 -0
- package/dist/chunk-3G37YKTV.mjs +83 -0
- package/dist/chunk-3JVFG7ER.mjs +184 -0
- package/dist/chunk-456TN7IM.mjs +110 -0
- package/dist/chunk-4EXYCTGJ.mjs +27 -0
- package/{src/utils/getSelectedNode.ts → dist/chunk-4HBCVSE6.mjs} +26 -27
- package/dist/chunk-4MEDW3T6.mjs +125 -0
- package/dist/chunk-4VWFVWYP.mjs +36 -0
- package/dist/chunk-5BAKY5KN.mjs +84 -0
- package/dist/chunk-5QSNIVIG.mjs +333 -0
- package/dist/chunk-64Z3FI7T.mjs +37 -0
- package/{src/components/editor/nodes/Stepper/index.tsx → dist/chunk-6RNZQOH2.mjs} +214 -260
- package/dist/chunk-77KXU36M.mjs +64 -0
- package/dist/chunk-77UA6HYR.mjs +165 -0
- package/dist/chunk-7NZAPJ4G.mjs +102 -0
- package/dist/chunk-7VUMHWWL.mjs +152 -0
- package/dist/chunk-AMMKBSST.mjs +1256 -0
- package/dist/chunk-BIU7WTLX.mjs +95 -0
- package/dist/chunk-EGMI62PP.mjs +83 -0
- package/dist/chunk-EHNQD5KO.mjs +88 -0
- package/dist/chunk-FSM26655.mjs +37 -0
- package/{src/components/editor/nodes/Hint/index.tsx → dist/chunk-G53GLEAY.mjs} +158 -190
- package/dist/chunk-GK35L7UY.mjs +28 -0
- package/dist/chunk-GXYD4VZM.mjs +193 -0
- package/dist/chunk-GYIOYVCN.mjs +538 -0
- package/dist/chunk-GZPNVR7L.mjs +157 -0
- package/dist/chunk-JXDPPUJI.mjs +52 -0
- package/dist/chunk-K36V4SIW.mjs +141 -0
- package/dist/chunk-KJ6AJ44Q.mjs +128 -0
- package/dist/chunk-KJV3FAZ7.mjs +142 -0
- package/{src/components/editor/plugins/ImagesPlugin/index.tsx → dist/chunk-LGG4IUIA.mjs} +189 -222
- package/dist/chunk-LQN3CMKV.mjs +1906 -0
- package/dist/chunk-N3WN46VL.mjs +236 -0
- package/dist/chunk-PBD6LMLC.mjs +366 -0
- package/dist/chunk-POGRR73N.mjs +33 -0
- package/{src/components/editor/utils/editorFormatting.ts → dist/chunk-PZSUSXQG.mjs} +238 -282
- package/dist/chunk-QEIFVK5M.mjs +29 -0
- package/dist/chunk-QHIQKMVN.mjs +427 -0
- package/dist/chunk-TCYK7DM7.mjs +36 -0
- package/dist/chunk-TTHQCW5F.mjs +47 -0
- package/dist/chunk-U47ABU5Z.mjs +53 -0
- package/dist/chunk-WDG7J2DY.mjs +116 -0
- package/dist/chunk-WJRHXI2C.mjs +733 -0
- package/dist/chunk-XLER2DHM.mjs +357 -0
- package/dist/chunk-XWC4TK2N.mjs +315 -0
- package/dist/chunk-YHPNOWFH.mjs +15 -0
- package/dist/chunk-YKC3SO4Z.mjs +32 -0
- package/dist/chunk-YMBXLRW5.mjs +374 -0
- package/dist/chunk-YPHOEJ46.mjs +64 -0
- package/dist/chunk-YUDCJRJM.mjs +25 -0
- package/dist/chunk-Z4EWP7BI.mjs +65 -0
- package/dist/chunk-ZB5LZQKC.mjs +191 -0
- package/dist/chunk-ZJRKATOJ.mjs +65 -0
- package/dist/color-BPKOPQKN.mjs +12 -0
- package/dist/estree-XC56IUFX.mjs +4414 -0
- package/dist/font-FEZ3GKSF.mjs +13 -0
- package/dist/font-size-EK775WRH.mjs +15 -0
- package/dist/html-S3ACX7NI.mjs +2738 -0
- package/dist/image-2PJIAYAT.mjs +993 -0
- package/dist/index.d.mts +145 -0
- package/dist/index.d.ts +145 -0
- package/dist/index.js +57855 -0
- package/dist/index.mjs +1790 -0
- package/dist/insert-gif-SAIDYURE.mjs +100 -0
- package/dist/insert-image-U3RJN3OW.mjs +259 -0
- package/dist/insert-node-5P2CRJ7S.mjs +201 -0
- package/dist/insert-poll-HCPM7MO6.mjs +33 -0
- package/dist/insert-table-24XYUS2W.mjs +66 -0
- package/dist/markdown-SNVBOSRA.mjs +3487 -0
- package/dist/poll-component-2R4MDLHS.mjs +303 -0
- package/dist/postcss-ONF3VDIM.mjs +5051 -0
- package/dist/standalone-EOIALU3M.mjs +2373 -0
- package/dist/stepper-FSARL6X6.mjs +304 -0
- package/dist/styles/notiq.css +1149 -0
- package/dist/text-align-VLECWO4H.mjs +118 -0
- package/dist/text-format-BG5WOOPZ.mjs +16 -0
- package/dist/typescript-AMPI6OVS.mjs +13135 -0
- package/package.json +66 -11
- package/src/styles/notiq.css +1149 -0
- package/src/styles/tailwind-plugin.ts +134 -0
- package/components.json +0 -21
- package/eslint.config.mjs +0 -16
- package/next.config.ts +0 -12
- package/postcss.config.mjs +0 -5
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/images/icons/plus.svg +0 -10
- package/public/next.svg +0 -1
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/src/app/actions.ts +0 -2
- package/src/app/api/ai/route.ts +0 -175
- package/src/app/api/edgestore/[...edgestore]/route.ts +0 -28
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -205
- package/src/app/layout.tsx +0 -38
- package/src/app/page.tsx +0 -12
- package/src/components/editor/Core.tsx +0 -220
- package/src/components/editor/hooks/instructions-messages.ts +0 -300
- package/src/components/editor/hooks/use-mobile.ts +0 -19
- package/src/components/editor/hooks/useReport.ts +0 -67
- package/src/components/editor/hooks/useResizeObservert.ts +0 -22
- package/src/components/editor/index.tsx +0 -39
- package/src/components/editor/lexical-on-change.tsx +0 -28
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +0 -92
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +0 -65
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +0 -105
- package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +0 -143
- package/src/components/editor/nodes/EquationNode/EquationNode.tsx +0 -170
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +0 -228
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +0 -137
- package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +0 -317
- package/src/components/editor/nodes/ExcalidrawNode/index.tsx +0 -204
- package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +0 -134
- package/src/components/editor/nodes/Hint/HintComponet.tsx +0 -221
- package/src/components/editor/nodes/ImageNode/index.tsx +0 -328
- package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +0 -383
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +0 -94
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +0 -309
- package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +0 -146
- package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +0 -79
- package/src/components/editor/nodes/PollNode/index.tsx +0 -204
- package/src/components/editor/nodes/TweetNode/index.tsx +0 -214
- package/src/components/editor/nodes/index.ts +0 -81
- package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +0 -350
- package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +0 -56
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +0 -70
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +0 -192
- package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +0 -217
- package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +0 -26
- package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +0 -21
- package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +0 -76
- package/src/components/editor/plugins/CollapsiblePlugin/index.ts +0 -228
- package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +0 -44
- package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +0 -52
- package/src/components/editor/plugins/EquationsPlugin/index.tsx +0 -85
- package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +0 -98
- package/src/components/editor/plugins/FigmaPlugin/index.tsx +0 -42
- package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +0 -445
- package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +0 -275
- package/src/components/editor/plugins/InlineImagePlugin/index.tsx +0 -351
- package/src/components/editor/plugins/LayoutPlugin/index.tsx +0 -238
- package/src/components/editor/plugins/LinkPlugin/index.tsx +0 -36
- package/src/components/editor/plugins/LinkWithMetaData/index.tsx +0 -271
- package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +0 -11
- package/src/components/editor/plugins/MarkdownTransformers/index.tsx +0 -304
- package/src/components/editor/plugins/PollPlugin/index.tsx +0 -49
- package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +0 -180
- package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +0 -253
- package/src/components/editor/plugins/SlashCommand/index.tsx +0 -621
- package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +0 -127
- package/src/components/editor/plugins/TabFocusPlugin/index.ts +0 -58
- package/src/components/editor/plugins/TableCellResizer/index.tsx +0 -438
- package/src/components/editor/plugins/TablePlugin/index.tsx +0 -99
- package/src/components/editor/plugins/ToolbarPlugin/index.tsx +0 -522
- package/src/components/editor/plugins/TwitterPlugin/index.ts +0 -35
- package/src/components/editor/plugins/YouTubeNode/index.tsx +0 -179
- package/src/components/editor/plugins/YouTubePlugin/index.ts +0 -41
- package/src/components/editor/themes/editor-theme.ts +0 -113
- package/src/components/editor/themes/theme.css +0 -377
- package/src/components/editor/utils/ai.ts +0 -291
- package/src/components/editor/utils/canUseDOM.ts +0 -12
- package/src/components/editor/utils/environment.ts +0 -50
- package/src/components/editor/utils/extract-data.ts +0 -166
- package/src/components/editor/utils/getAllLexicalChildren.ts +0 -13
- package/src/components/editor/utils/getDOMRangeRect.ts +0 -27
- package/src/components/editor/utils/getSelectedNode.ts +0 -27
- package/src/components/editor/utils/gif.ts +0 -29
- package/src/components/editor/utils/invariant.ts +0 -15
- package/src/components/editor/utils/setFloatingElemPosition.ts +0 -51
- package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +0 -40
- package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +0 -51
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +0 -15
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +0 -114
- package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +0 -6
- package/src/components/editor/utils/url.ts +0 -109
- package/src/components/editor/utils/useLayoutEffect.ts +0 -13
- package/src/components/providers/QueryProvider.tsx +0 -15
- package/src/components/providers/SharedHistoryContext.tsx +0 -28
- package/src/components/providers/ToolbarContext.tsx +0 -123
- package/src/components/providers/theme-provider.tsx +0 -11
- package/src/components/theme/ModeToggle.tsx +0 -40
- package/src/components/ui/FileInput.tsx +0 -40
- package/src/components/ui/Input.css +0 -32
- package/src/components/ui/Select.css +0 -42
- package/src/components/ui/Select.tsx +0 -36
- package/src/components/ui/TextInput.tsx +0 -48
- package/src/components/ui/ai/ai-button.tsx +0 -574
- package/src/components/ui/ai/border.tsx +0 -99
- package/src/components/ui/ai/placeholder-input-vanish.tsx +0 -282
- package/src/components/ui/button.tsx +0 -89
- package/src/components/ui/card.tsx +0 -76
- package/src/components/ui/checkbox.tsx +0 -30
- package/src/components/ui/command.tsx +0 -153
- package/src/components/ui/dialog/Dialog.css +0 -25
- package/src/components/ui/dialog/Dialog.tsx +0 -34
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/drop-downs/background-color.tsx +0 -183
- package/src/components/ui/drop-downs/block-format.tsx +0 -159
- package/src/components/ui/drop-downs/code.tsx +0 -42
- package/src/components/ui/drop-downs/color.tsx +0 -177
- package/src/components/ui/drop-downs/font-size.tsx +0 -138
- package/src/components/ui/drop-downs/font.tsx +0 -155
- package/src/components/ui/drop-downs/index.tsx +0 -122
- package/src/components/ui/drop-downs/insert-node.tsx +0 -213
- package/src/components/ui/drop-downs/text-align.tsx +0 -123
- package/src/components/ui/drop-downs/text-format.tsx +0 -104
- package/src/components/ui/dropdown-menu.tsx +0 -201
- package/src/components/ui/equation/EquationEditor.css +0 -38
- package/src/components/ui/equation/EquationEditor.tsx +0 -56
- package/src/components/ui/equation/KatexEquationAlterer.css +0 -41
- package/src/components/ui/equation/KatexEquationAlterer.tsx +0 -83
- package/src/components/ui/equation/KatexRenderer.tsx +0 -66
- package/src/components/ui/excalidraw/ExcalidrawModal.css +0 -64
- package/src/components/ui/excalidraw/ExcalidrawModal.tsx +0 -234
- package/src/components/ui/excalidraw/Modal.css +0 -62
- package/src/components/ui/excalidraw/Modal.tsx +0 -110
- package/src/components/ui/hover-card.tsx +0 -29
- package/src/components/ui/image/error-image.tsx +0 -17
- package/src/components/ui/image/file-upload.tsx +0 -240
- package/src/components/ui/image/image-resizer.tsx +0 -297
- package/src/components/ui/image/image-toolbar.tsx +0 -264
- package/src/components/ui/image/index.tsx +0 -408
- package/src/components/ui/image/lazy-image.tsx +0 -68
- package/src/components/ui/image/lazy-video.tsx +0 -71
- package/src/components/ui/input.tsx +0 -22
- package/src/components/ui/models/custom-dialog.tsx +0 -320
- package/src/components/ui/models/insert-gif.tsx +0 -90
- package/src/components/ui/models/insert-image.tsx +0 -52
- package/src/components/ui/models/insert-poll.tsx +0 -29
- package/src/components/ui/models/insert-table.tsx +0 -62
- package/src/components/ui/models/use-model.tsx +0 -91
- package/src/components/ui/poll/poll-component.tsx +0 -304
- package/src/components/ui/popover.tsx +0 -33
- package/src/components/ui/progress.tsx +0 -28
- package/src/components/ui/scroll-area.tsx +0 -48
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/skeleton.tsx +0 -15
- package/src/components/ui/sonner.tsx +0 -31
- package/src/components/ui/stepper/step.tsx +0 -179
- package/src/components/ui/stepper/stepper.tsx +0 -89
- package/src/components/ui/textarea.tsx +0 -22
- package/src/components/ui/toggle.tsx +0 -71
- package/src/components/ui/tooltip.tsx +0 -32
- package/src/components/ui/write/text-format-floting-toolbar.tsx +0 -346
- package/src/lib/edgestore.ts +0 -9
- package/src/lib/pinecone-client.ts +0 -0
- package/src/lib/utils.ts +0 -6
- package/src/utils/docSerialization.ts +0 -77
- package/src/utils/emoji-list.ts +0 -16615
- package/src/utils/getDOMRangeRect.ts +0 -27
- package/src/utils/getThemeSelector.ts +0 -25
- package/src/utils/isMobileWidth.ts +0 -7
- package/src/utils/joinClasses.ts +0 -13
- package/src/utils/setFloatingElemPosition.ts +0 -74
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +0 -46
- package/src/utils/swipe.ts +0 -127
- package/src/utils/url.ts +0 -38
- package/tsconfig.json +0 -27
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { $createCodeNode } from "@lexical/code";
|
|
2
|
-
import {
|
|
3
|
-
$createParagraphNode,
|
|
4
|
-
$createRangeSelection,
|
|
5
|
-
$createTextNode,
|
|
6
|
-
$getRoot,
|
|
7
|
-
$getSelection,
|
|
8
|
-
$isRangeSelection,
|
|
9
|
-
$isTextNode,
|
|
10
|
-
createEditor,
|
|
11
|
-
ElementNode,
|
|
12
|
-
LexicalEditor,
|
|
13
|
-
LexicalNode,
|
|
14
|
-
TextNode,
|
|
15
|
-
} from "lexical";
|
|
16
|
-
import {
|
|
17
|
-
$createHeadingNode,} from '@lexical/rich-text';
|
|
18
|
-
import { $createStepperNode, StepsType } from "../nodes/Stepper";
|
|
19
|
-
|
|
20
|
-
function getWordsBeforeSelection(
|
|
21
|
-
editor: LexicalEditor,
|
|
22
|
-
numWords: number
|
|
23
|
-
): string {
|
|
24
|
-
let wordsBeforeSelection = "";
|
|
25
|
-
|
|
26
|
-
editor.update(() => {
|
|
27
|
-
const selection = $getSelection();
|
|
28
|
-
if (!$isRangeSelection(selection)) {
|
|
29
|
-
console.warn("No valid text selection found.");
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const anchor = selection.anchor;
|
|
34
|
-
const firstTextNode = findFirstTextNode($getRoot());
|
|
35
|
-
|
|
36
|
-
if (!firstTextNode) {
|
|
37
|
-
console.warn("No text nodes found in the document.");
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Create a range from the first text node start to the selection anchor
|
|
42
|
-
const range = $createRangeSelection();
|
|
43
|
-
range.anchor.set(firstTextNode.__key, 0, 'text');
|
|
44
|
-
range.focus.set(anchor.key, anchor.offset, anchor.type);
|
|
45
|
-
|
|
46
|
-
const textContent = range.getTextContent();
|
|
47
|
-
const words = textContent.split(/\s+/).filter(word => word.length > 0);
|
|
48
|
-
|
|
49
|
-
const startIndex = Math.max(0, words.length - numWords);
|
|
50
|
-
wordsBeforeSelection = words.slice(startIndex, words.length).join(" ");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return wordsBeforeSelection;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Helper function to find the first text node in document order
|
|
57
|
-
function findFirstTextNode(node: LexicalNode): TextNode | null {
|
|
58
|
-
if ($isTextNode(node)) {
|
|
59
|
-
return node;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const children = (node as ElementNode).getChildren();
|
|
63
|
-
for (const child of children) {
|
|
64
|
-
const result = findFirstTextNode(child);
|
|
65
|
-
if (result) {
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function isJSON(text: string): boolean {
|
|
75
|
-
try {
|
|
76
|
-
JSON.parse(text);
|
|
77
|
-
return true;
|
|
78
|
-
} catch (err) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function createEditorWithText(text: string): LexicalEditor {
|
|
83
|
-
const editor = createEditor();
|
|
84
|
-
const editorState = editor.parseEditorState(
|
|
85
|
-
JSON.stringify({
|
|
86
|
-
root: {
|
|
87
|
-
children: [
|
|
88
|
-
{
|
|
89
|
-
children: [
|
|
90
|
-
{
|
|
91
|
-
detail: 0,
|
|
92
|
-
format: 0,
|
|
93
|
-
mode: "normal",
|
|
94
|
-
style: "",
|
|
95
|
-
text: text,
|
|
96
|
-
type: "text",
|
|
97
|
-
version: 1,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
direction: null,
|
|
101
|
-
format: "",
|
|
102
|
-
indent: 0,
|
|
103
|
-
type: "paragraph",
|
|
104
|
-
version: 1,
|
|
105
|
-
textFormat: 0,
|
|
106
|
-
textStyle: "",
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
direction: null,
|
|
110
|
-
format: "",
|
|
111
|
-
indent: 0,
|
|
112
|
-
type: "root",
|
|
113
|
-
version: 1,
|
|
114
|
-
},
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
editor.setEditorState(editorState);
|
|
118
|
-
return editor;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function GenerateSteps(json:string, editor: LexicalEditor){
|
|
122
|
-
const stepsData = JSON.parse(json);
|
|
123
|
-
const steps: StepsType = stepsData.map((step: { id: number; title: string; content: string }) => {
|
|
124
|
-
return {
|
|
125
|
-
id: step.id,
|
|
126
|
-
title: step.title,
|
|
127
|
-
content: createEditorWithText(step.content),
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
editor.update(()=>{
|
|
131
|
-
const selection = $getSelection();
|
|
132
|
-
if ($isRangeSelection(selection)) {
|
|
133
|
-
const stepperNode = $createStepperNode(steps);
|
|
134
|
-
selection.insertNodes([stepperNode]);
|
|
135
|
-
}
|
|
136
|
-
return
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// getMore = number of words to get if the selection was less than 30 len.
|
|
141
|
-
const getSelectedText = (editor: LexicalEditor,getMore?:number) => {
|
|
142
|
-
let selectedText = "";
|
|
143
|
-
let context = getMore?getWordsBeforeSelection(editor, getMore):null
|
|
144
|
-
editor.update(() => {
|
|
145
|
-
const selection = $getSelection();
|
|
146
|
-
if ($isRangeSelection(selection)) {
|
|
147
|
-
const selectionText = selection.getTextContent();
|
|
148
|
-
if (selectionText.length > 30) {
|
|
149
|
-
selectedText = selectionText;
|
|
150
|
-
} else {
|
|
151
|
-
selectedText = context+selectionText ;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return selectedText;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function applyStyles(AIString: string) {
|
|
161
|
-
// Regex now matches:
|
|
162
|
-
// 1. Code blocks delimited by triple backticks (```...```)
|
|
163
|
-
// 2. Bold text delimited by ** (e.g., **bold**)
|
|
164
|
-
// 3. Inline code delimited by a single backtick (e.g., `some code`)
|
|
165
|
-
// 4. Headers starting with ### (e.g., ### Header)
|
|
166
|
-
const pattern = /(```[\s\S]*?```)|(\*\*[\s\S]+?\*\*)|(`[\s\S]+?`)|(###\s+[\s\S]+?(?=\n|$))/g;
|
|
167
|
-
let lastIndex = 0;
|
|
168
|
-
const nodes = [];
|
|
169
|
-
|
|
170
|
-
// Process all matches of code, bold, or inline code segments.
|
|
171
|
-
AIString.replace(
|
|
172
|
-
pattern,
|
|
173
|
-
(match, codeBlockMatch, boldMatch, codeMatch,headerMatch, offset) => {
|
|
174
|
-
// Append any plain text before the matched segment.
|
|
175
|
-
if (offset > lastIndex) {
|
|
176
|
-
const plainText = AIString.slice(lastIndex, offset);
|
|
177
|
-
nodes.push($createTextNode(plainText));
|
|
178
|
-
}
|
|
179
|
-
if (codeBlockMatch) {
|
|
180
|
-
// TODO: extract the code lang and apply it to the code block.
|
|
181
|
-
|
|
182
|
-
const content = codeBlockMatch.slice(3, -3);
|
|
183
|
-
const codeNode = $createCodeNode();
|
|
184
|
-
codeNode.append($createTextNode(content));
|
|
185
|
-
nodes.push(codeNode);
|
|
186
|
-
} else if (boldMatch) {
|
|
187
|
-
// Found bold text. Remove the leading and trailing "**".
|
|
188
|
-
const content = boldMatch.slice(2, -2);
|
|
189
|
-
const boldTextNode = $createTextNode(content);
|
|
190
|
-
boldTextNode.setFormat("bold");
|
|
191
|
-
nodes.push(boldTextNode);
|
|
192
|
-
} else if (codeMatch) {
|
|
193
|
-
const content = codeMatch.slice(1, -1);
|
|
194
|
-
const codeTextNode = $createTextNode(content);
|
|
195
|
-
codeTextNode.setFormat("code");
|
|
196
|
-
nodes.push(codeTextNode);
|
|
197
|
-
}else if(headerMatch){
|
|
198
|
-
const content = headerMatch.slice(4).trim();
|
|
199
|
-
const headerNode = $createHeadingNode("h3");
|
|
200
|
-
headerNode.append($createTextNode(content));
|
|
201
|
-
nodes.push(headerNode);
|
|
202
|
-
}
|
|
203
|
-
lastIndex = offset + match.length;
|
|
204
|
-
return match;
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
// Append any remaining plain text after the last match.
|
|
209
|
-
if (lastIndex < AIString.length) {
|
|
210
|
-
nodes.push($createTextNode(AIString.slice(lastIndex)));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return nodes;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
function insertText(text: string, editor: LexicalEditor) {
|
|
218
|
-
if(isJSON(text) || text.startsWith("json")){
|
|
219
|
-
GenerateSteps(text,editor)
|
|
220
|
-
return
|
|
221
|
-
}
|
|
222
|
-
editor.update(() => {
|
|
223
|
-
const selection = $getSelection();
|
|
224
|
-
if (!$isRangeSelection(selection))
|
|
225
|
-
return console.log("No valid text selection found.");
|
|
226
|
-
|
|
227
|
-
const nodesInSelection = selection.getNodes();
|
|
228
|
-
if (nodesInSelection.length > 0) {
|
|
229
|
-
let insertionPoint = nodesInSelection[nodesInSelection.length - 1];
|
|
230
|
-
const formattedNodes = applyStyles(text);
|
|
231
|
-
|
|
232
|
-
formattedNodes.forEach((node: any) => {
|
|
233
|
-
insertionPoint.insertAfter(node);
|
|
234
|
-
insertionPoint = node;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function replaceSelectedText(text: string, editor: LexicalEditor) {
|
|
241
|
-
|
|
242
|
-
if(isJSON(text) || text.startsWith("json")){
|
|
243
|
-
GenerateSteps(text,editor)
|
|
244
|
-
return
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
editor.update(() => {
|
|
249
|
-
const selection = $getSelection();
|
|
250
|
-
if (!$isRangeSelection(selection)) {
|
|
251
|
-
console.warn("No valid text selection found.");
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
selection.removeText();
|
|
255
|
-
const formattedNodes = applyStyles(text);
|
|
256
|
-
selection.insertNodes(formattedNodes);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
function insertTextUnderSelected(text: string, editor: LexicalEditor) {
|
|
262
|
-
if(isJSON(text) || text.startsWith("json")){
|
|
263
|
-
GenerateSteps(text,editor)
|
|
264
|
-
return
|
|
265
|
-
}
|
|
266
|
-
editor.update(() => {
|
|
267
|
-
const selection = $getSelection();
|
|
268
|
-
if (!$isRangeSelection(selection)) return;
|
|
269
|
-
|
|
270
|
-
const nodes = selection.getNodes();
|
|
271
|
-
if (nodes.length > 0) {
|
|
272
|
-
const lastNode = nodes[nodes.length - 1];
|
|
273
|
-
|
|
274
|
-
const newParagraph = $createParagraphNode();
|
|
275
|
-
|
|
276
|
-
const formattedNodes = applyStyles(text);
|
|
277
|
-
|
|
278
|
-
newParagraph.append(...formattedNodes);
|
|
279
|
-
|
|
280
|
-
lastNode.insertAfter(newParagraph);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export {
|
|
286
|
-
replaceSelectedText,
|
|
287
|
-
insertTextUnderSelected,
|
|
288
|
-
getSelectedText,
|
|
289
|
-
insertText,
|
|
290
|
-
getWordsBeforeSelection,
|
|
291
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const CAN_USE_DOM: boolean =
|
|
10
|
-
typeof window !== 'undefined' &&
|
|
11
|
-
typeof window.document !== 'undefined' &&
|
|
12
|
-
typeof window.document.createElement !== 'undefined';
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {CAN_USE_DOM} from './canUseDOM';
|
|
4
|
-
|
|
5
|
-
declare global {
|
|
6
|
-
interface Document {
|
|
7
|
-
documentMode?: unknown;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface Window {
|
|
11
|
-
MSStream?: unknown;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const documentMode =
|
|
16
|
-
CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
17
|
-
|
|
18
|
-
export const IS_APPLE: boolean =
|
|
19
|
-
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
20
|
-
|
|
21
|
-
export const IS_FIREFOX: boolean =
|
|
22
|
-
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
23
|
-
|
|
24
|
-
export const CAN_USE_BEFORE_INPUT: boolean =
|
|
25
|
-
CAN_USE_DOM && 'InputEvent' in window && !documentMode
|
|
26
|
-
? 'getTargetRanges' in new window.InputEvent('input')
|
|
27
|
-
: false;
|
|
28
|
-
|
|
29
|
-
export const IS_SAFARI: boolean =
|
|
30
|
-
CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
31
|
-
|
|
32
|
-
export const IS_IOS: boolean =
|
|
33
|
-
CAN_USE_DOM &&
|
|
34
|
-
/iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
35
|
-
!window.MSStream;
|
|
36
|
-
|
|
37
|
-
export const IS_ANDROID: boolean =
|
|
38
|
-
CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
39
|
-
|
|
40
|
-
// Keep these in case we need to use them in the future.
|
|
41
|
-
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
42
|
-
export const IS_CHROME: boolean =
|
|
43
|
-
CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
44
|
-
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
45
|
-
|
|
46
|
-
export const IS_ANDROID_CHROME: boolean =
|
|
47
|
-
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
48
|
-
|
|
49
|
-
export const IS_APPLE_WEBKIT =
|
|
50
|
-
CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { $getRoot, ElementNode, LexicalEditor, ParagraphNode, TextNode } from "lexical";
|
|
2
|
-
import {ListItemNode, ListNode} from "@lexical/list"
|
|
3
|
-
import {HeadingNode,QuoteNode} from "@lexical/rich-text"
|
|
4
|
-
import {TableNode} from "@lexical/table"
|
|
5
|
-
import {CodeNode} from "@lexical/code"
|
|
6
|
-
import { CollapsibleContainerNode } from "../nodes/CollapsibleNode/CollapsibleContainerNode";
|
|
7
|
-
import { CollapsibleTitleNode } from "../nodes/CollapsibleNode/CollapsibleTitleNode";
|
|
8
|
-
export type BlockType = "Table"|'heading'|"CollapsibleContent" | 'paragraph' |"Collapsible"| 'text' | 'list' | 'list-item' | 'quote' | 'code' | "Hint"
|
|
9
|
-
|
|
10
|
-
export type ExtractedBlock = {
|
|
11
|
-
blockType: BlockType;
|
|
12
|
-
content: string;
|
|
13
|
-
children?: ExtractedBlock[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function extractChildrenContent(nodes: any[]): string {
|
|
17
|
-
return nodes
|
|
18
|
-
.filter(node => node instanceof TextNode)
|
|
19
|
-
.map(node => node.getTextContent())
|
|
20
|
-
.join(' ');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function processListItem(listItem: ListItemNode): ExtractedBlock {
|
|
24
|
-
let textContent = '';
|
|
25
|
-
const children: ExtractedBlock[] = [];
|
|
26
|
-
|
|
27
|
-
listItem.getChildren().forEach(child => {
|
|
28
|
-
if (child instanceof TextNode) {
|
|
29
|
-
textContent += child.getTextContent();
|
|
30
|
-
} else if (child instanceof ElementNode) {
|
|
31
|
-
textContent += extractChildrenContent(child.getChildren());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (child instanceof ListNode) {
|
|
35
|
-
children.push(...processList(child));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
blockType: 'list-item',
|
|
41
|
-
content: textContent.trim(),
|
|
42
|
-
children: children.length > 0 ? children : undefined
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function processList(listNode: ListNode): ExtractedBlock[] {
|
|
47
|
-
const listType = listNode.getListType();
|
|
48
|
-
return listNode.getChildren().map(child => ({
|
|
49
|
-
...processListItem(child as ListItemNode),
|
|
50
|
-
attributes: { listType }
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function processHeading(headingNode: HeadingNode): ExtractedBlock {
|
|
55
|
-
return {
|
|
56
|
-
blockType: 'heading',
|
|
57
|
-
content: headingNode.getTextContent(),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
// should i make better json?
|
|
61
|
-
function processTable(TableNode:TableNode): ExtractedBlock {
|
|
62
|
-
return {
|
|
63
|
-
blockType: 'Table',
|
|
64
|
-
content: TableNode.getTextContent(),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function processCodeBlock(codeNode: CodeNode): ExtractedBlock {
|
|
68
|
-
return {
|
|
69
|
-
blockType: 'code',
|
|
70
|
-
content: codeNode.getTextContent(),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function ExtractData(editor: LexicalEditor):string {
|
|
75
|
-
const blocks: ExtractedBlock[] = [];
|
|
76
|
-
|
|
77
|
-
editor.update(() => {
|
|
78
|
-
const root = $getRoot();
|
|
79
|
-
|
|
80
|
-
root.getChildren().forEach(node => {
|
|
81
|
-
try {
|
|
82
|
-
|
|
83
|
-
if (node instanceof HeadingNode) {
|
|
84
|
-
blocks.push(processHeading(node));
|
|
85
|
-
}
|
|
86
|
-
else if(node instanceof TableNode){
|
|
87
|
-
blocks.push(processTable(node));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
else if (node instanceof ListNode) {
|
|
91
|
-
blocks.push({
|
|
92
|
-
blockType: 'list',
|
|
93
|
-
content: '',
|
|
94
|
-
children: processList(node)
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else if (node instanceof CollapsibleContainerNode || node instanceof CollapsibleTitleNode) {
|
|
98
|
-
let title = "";
|
|
99
|
-
let content = "";
|
|
100
|
-
|
|
101
|
-
if (node instanceof CollapsibleTitleNode) {
|
|
102
|
-
title = node.getTextContent();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (node instanceof CollapsibleContainerNode) {
|
|
106
|
-
const children = node.getChildren();
|
|
107
|
-
const titleNode = children.find(child => child instanceof CollapsibleTitleNode);
|
|
108
|
-
if (titleNode) {
|
|
109
|
-
title = titleNode.getTextContent();
|
|
110
|
-
}
|
|
111
|
-
content = children
|
|
112
|
-
.filter(child => !(child instanceof CollapsibleTitleNode))
|
|
113
|
-
.map(child => child.getTextContent())
|
|
114
|
-
.join("\n");
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
blocks.push({
|
|
119
|
-
blockType: "Collapsible",
|
|
120
|
-
content: title, // The collapsible title.
|
|
121
|
-
children: [
|
|
122
|
-
{
|
|
123
|
-
blockType: "CollapsibleContent",
|
|
124
|
-
content: content, // The collapsible content.
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
else if (node instanceof ParagraphNode) {
|
|
130
|
-
if(node.getTextContent() == "") return;
|
|
131
|
-
blocks.push({
|
|
132
|
-
blockType: 'paragraph',
|
|
133
|
-
content: node.getTextContent()
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
else if (node instanceof CodeNode) {
|
|
137
|
-
blocks.push(processCodeBlock(node));
|
|
138
|
-
}
|
|
139
|
-
else if (node instanceof QuoteNode) {
|
|
140
|
-
|
|
141
|
-
blocks.push({
|
|
142
|
-
blockType: 'quote',
|
|
143
|
-
content: node.getTextContent(),
|
|
144
|
-
children: node.getChildren().length>=2 ?node.getChildren().map(child => ({
|
|
145
|
-
blockType: 'text',
|
|
146
|
-
content: child.getTextContent()
|
|
147
|
-
})):undefined
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
else if (node instanceof TextNode) {
|
|
151
|
-
blocks.push({
|
|
152
|
-
blockType: 'text',
|
|
153
|
-
content: node.getTextContent()
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
} catch (error) {
|
|
158
|
-
console.warn('Error processing node:', error);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return JSON.stringify(blocks);
|
|
166
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { $getNodeByKey, $getRoot, LexicalEditor } from 'lexical';
|
|
2
|
-
|
|
3
|
-
export const getAllLexicalChildren = (editor: LexicalEditor) => {
|
|
4
|
-
const childrenKeys = editor
|
|
5
|
-
.getEditorState()
|
|
6
|
-
.read(() => $getRoot().getChildrenKeys());
|
|
7
|
-
|
|
8
|
-
return childrenKeys.map((key) => ({
|
|
9
|
-
key: key,
|
|
10
|
-
node: $getNodeByKey(key),
|
|
11
|
-
htmlElement: editor.getElementByKey(key),
|
|
12
|
-
}));
|
|
13
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
export function getDOMRangeRect(
|
|
9
|
-
nativeSelection: Selection,
|
|
10
|
-
rootElement: HTMLElement,
|
|
11
|
-
): DOMRect {
|
|
12
|
-
const domRange = nativeSelection.getRangeAt(0);
|
|
13
|
-
|
|
14
|
-
let rect;
|
|
15
|
-
|
|
16
|
-
if (nativeSelection.anchorNode === rootElement) {
|
|
17
|
-
let inner = rootElement;
|
|
18
|
-
while (inner.firstElementChild != null) {
|
|
19
|
-
inner = inner.firstElementChild as HTMLElement;
|
|
20
|
-
}
|
|
21
|
-
rect = inner.getBoundingClientRect();
|
|
22
|
-
} else {
|
|
23
|
-
rect = domRange.getBoundingClientRect();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return rect;
|
|
27
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
import {$isAtNodeEnd} from '@lexical/selection';
|
|
9
|
-
import {ElementNode, RangeSelection, TextNode} from 'lexical';
|
|
10
|
-
|
|
11
|
-
export function getSelectedNode(
|
|
12
|
-
selection: RangeSelection,
|
|
13
|
-
): TextNode | ElementNode {
|
|
14
|
-
const anchor = selection.anchor;
|
|
15
|
-
const focus = selection.focus;
|
|
16
|
-
const anchorNode = selection.anchor.getNode();
|
|
17
|
-
const focusNode = selection.focus.getNode();
|
|
18
|
-
if (anchorNode === focusNode) {
|
|
19
|
-
return anchorNode;
|
|
20
|
-
}
|
|
21
|
-
const isBackward = selection.isBackward();
|
|
22
|
-
if (isBackward) {
|
|
23
|
-
return $isAtNodeEnd(focus) ? anchorNode : focusNode;
|
|
24
|
-
} else {
|
|
25
|
-
return $isAtNodeEnd(anchor) ? anchorNode : focusNode;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const API_KEY = process.env.NEXT_PUBLIC_TENOR_API_KEY;
|
|
3
|
-
|
|
4
|
-
const fetchGifs = async ({ q = "trending" }: { q?: string }) => {
|
|
5
|
-
const params = new URLSearchParams({
|
|
6
|
-
key: API_KEY || '',
|
|
7
|
-
q,
|
|
8
|
-
limit: "200",
|
|
9
|
-
media_filter: 'minimal',
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const response = await fetch(`https://tenor.googleapis.com/v2/search?${params.toString()}`);
|
|
13
|
-
|
|
14
|
-
if (!response.ok) {
|
|
15
|
-
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const data = await response.json();
|
|
19
|
-
|
|
20
|
-
const gifs = data.results.map((gif: any) => ({
|
|
21
|
-
id: gif.id,
|
|
22
|
-
url: gif.media_formats.gif.url,
|
|
23
|
-
alt_text: gif.content_description,
|
|
24
|
-
}));
|
|
25
|
-
|
|
26
|
-
return { gifs, next: data.next };
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default fetchGifs;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default function invariant(
|
|
3
|
-
cond?: boolean,
|
|
4
|
-
message?: string,
|
|
5
|
-
): asserts cond {
|
|
6
|
-
if (cond) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
throw new Error(
|
|
11
|
-
'Internal Lexical error: invariant() is meant to be replaced at compile ' +
|
|
12
|
-
'time. There is no runtime version. Error: ' +
|
|
13
|
-
message,
|
|
14
|
-
);
|
|
15
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
const VERTICAL_GAP = 10;
|
|
2
|
-
const HORIZONTAL_OFFSET = 5;
|
|
3
|
-
|
|
4
|
-
export function setFloatingElemPosition(
|
|
5
|
-
targetRect: DOMRect | null,
|
|
6
|
-
floatingElem: HTMLElement,
|
|
7
|
-
anchorElem: HTMLElement,
|
|
8
|
-
verticalGap: number = VERTICAL_GAP,
|
|
9
|
-
horizontalOffset: number = HORIZONTAL_OFFSET,
|
|
10
|
-
): void {
|
|
11
|
-
const scrollerElem = anchorElem.parentElement;
|
|
12
|
-
|
|
13
|
-
if (targetRect === null || !scrollerElem) {
|
|
14
|
-
floatingElem.style.opacity = '0';
|
|
15
|
-
floatingElem.style.transform = 'translate(-10000px, -10000px)';
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const floatingElemRect = floatingElem.getBoundingClientRect();
|
|
20
|
-
const anchorElementRect = anchorElem.getBoundingClientRect();
|
|
21
|
-
const editorScrollerRect = scrollerElem.getBoundingClientRect();
|
|
22
|
-
|
|
23
|
-
// Calculate initial top and left positions
|
|
24
|
-
let top = targetRect.bottom + verticalGap;
|
|
25
|
-
let left = targetRect.left + horizontalOffset;
|
|
26
|
-
|
|
27
|
-
// Ensure the floating element stays within the editor's bounds
|
|
28
|
-
if (top + floatingElemRect.height > editorScrollerRect.bottom) {
|
|
29
|
-
// If it overflows at the bottom, position it above the selection
|
|
30
|
-
top = targetRect.top - floatingElemRect.height - verticalGap;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (left + floatingElemRect.width > editorScrollerRect.right) {
|
|
34
|
-
// If it overflows on the right, align it with the right edge of the editor
|
|
35
|
-
left = editorScrollerRect.right - floatingElemRect.width - horizontalOffset;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (left < editorScrollerRect.left) {
|
|
39
|
-
// If it overflows on the left, align it with the left edge of the editor
|
|
40
|
-
left = editorScrollerRect.left + horizontalOffset;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Adjust for the anchor element's position
|
|
44
|
-
top -= anchorElementRect.top;
|
|
45
|
-
left -= anchorElementRect.left;
|
|
46
|
-
|
|
47
|
-
// Apply smooth transition and positioning
|
|
48
|
-
floatingElem.style.transition = 'transform 0.2s ease-in-out, opacity 0.2s ease-in-out';
|
|
49
|
-
floatingElem.style.opacity = '1';
|
|
50
|
-
floatingElem.style.transform = `translate(${left}px, ${top}px)`;
|
|
51
|
-
}
|