@collabchron/notiq 0.2.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/README.md +71 -0
- package/components.json +21 -0
- package/eslint.config.mjs +16 -0
- package/next.config.ts +12 -0
- package/package.json +108 -0
- package/postcss.config.mjs +5 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/images/icons/plus.svg +10 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/actions.ts +2 -0
- package/src/app/api/ai/route.ts +175 -0
- package/src/app/api/edgestore/[...edgestore]/route.ts +28 -0
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +205 -0
- package/src/app/layout.tsx +38 -0
- package/src/app/page.tsx +12 -0
- package/src/components/editor/Core.tsx +220 -0
- package/src/components/editor/hooks/instructions-messages.ts +300 -0
- package/src/components/editor/hooks/use-mobile.ts +19 -0
- package/src/components/editor/hooks/useReport.ts +67 -0
- package/src/components/editor/hooks/useResizeObservert.ts +22 -0
- package/src/components/editor/index.tsx +39 -0
- package/src/components/editor/lexical-on-change.tsx +28 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContainerNode.ts +92 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleContentNode.ts +65 -0
- package/src/components/editor/nodes/CollapsibleNode/CollapsibleTitleNode.ts +105 -0
- package/src/components/editor/nodes/EquationNode/EquationComponent.tsx +143 -0
- package/src/components/editor/nodes/EquationNode/EquationNode.tsx +170 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawComponent.tsx +228 -0
- package/src/components/editor/nodes/ExcalidrawNode/ExcalidrawImage.tsx +137 -0
- package/src/components/editor/nodes/ExcalidrawNode/ImageResizer.tsx +317 -0
- package/src/components/editor/nodes/ExcalidrawNode/index.tsx +204 -0
- package/src/components/editor/nodes/FigmaNode/FigmaNode.tsx +134 -0
- package/src/components/editor/nodes/Hint/HintComponet.tsx +221 -0
- package/src/components/editor/nodes/Hint/index.tsx +190 -0
- package/src/components/editor/nodes/ImageNode/index.tsx +328 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageComponent.tsx +383 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.css +94 -0
- package/src/components/editor/nodes/InlineImageNode/InlineImageNode.tsx +309 -0
- package/src/components/editor/nodes/LayoutNode/LayoutContainerNode.ts +146 -0
- package/src/components/editor/nodes/LayoutNode/LayoutItemNode.ts +79 -0
- package/src/components/editor/nodes/PollNode/index.tsx +204 -0
- package/src/components/editor/nodes/Stepper/index.tsx +260 -0
- package/src/components/editor/nodes/TweetNode/index.tsx +214 -0
- package/src/components/editor/nodes/index.ts +81 -0
- package/src/components/editor/plugins/AutoEmbedPlugin/index.tsx +350 -0
- package/src/components/editor/plugins/AutoLinkPlugin/index.tsx +56 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/CopyButton.tsx +70 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/components/PrettierButton.tsx +192 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/index.tsx +217 -0
- package/src/components/editor/plugins/CodeActionMenuPlugin/utils.ts +26 -0
- package/src/components/editor/plugins/CodeHighlightPlugin/index.ts +21 -0
- package/src/components/editor/plugins/CollapsiblePlugin/Collapsible.css +76 -0
- package/src/components/editor/plugins/CollapsiblePlugin/index.ts +228 -0
- package/src/components/editor/plugins/DragDropPastePlugin/index.tsx +44 -0
- package/src/components/editor/plugins/DraggableBlockPlugin/index.tsx +52 -0
- package/src/components/editor/plugins/EquationsPlugin/index.tsx +85 -0
- package/src/components/editor/plugins/ExcalidrawPlugin/index.tsx +98 -0
- package/src/components/editor/plugins/FigmaPlugin/index.tsx +42 -0
- package/src/components/editor/plugins/FloatingLinkEditorPlugin/index.tsx +445 -0
- package/src/components/editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +275 -0
- package/src/components/editor/plugins/ImagesPlugin/index.tsx +222 -0
- package/src/components/editor/plugins/InlineImagePlugin/index.tsx +351 -0
- package/src/components/editor/plugins/LayoutPlugin/index.tsx +238 -0
- package/src/components/editor/plugins/LinkPlugin/index.tsx +36 -0
- package/src/components/editor/plugins/LinkWithMetaData/index.tsx +271 -0
- package/src/components/editor/plugins/MarkdownShortcutPlugin/index.tsx +11 -0
- package/src/components/editor/plugins/MarkdownTransformers/index.tsx +304 -0
- package/src/components/editor/plugins/PollPlugin/index.tsx +49 -0
- package/src/components/editor/plugins/ShortcutsPlugin/index.tsx +180 -0
- package/src/components/editor/plugins/ShortcutsPlugin/shortcuts.ts +253 -0
- package/src/components/editor/plugins/SlashCommand/index.tsx +621 -0
- package/src/components/editor/plugins/SpeechToTextPlugin/index.ts +127 -0
- package/src/components/editor/plugins/TabFocusPlugin/index.ts +58 -0
- package/src/components/editor/plugins/TableCellActionMenuPlugin/index.tsx +759 -0
- package/src/components/editor/plugins/TableCellResizer/index.tsx +438 -0
- package/src/components/editor/plugins/TableHoverActionsPlugin/index.tsx +314 -0
- package/src/components/editor/plugins/TablePlugin/index.tsx +99 -0
- package/src/components/editor/plugins/ToolbarPlugin/index.tsx +522 -0
- package/src/components/editor/plugins/TwitterPlugin/index.ts +35 -0
- package/src/components/editor/plugins/YouTubeNode/index.tsx +179 -0
- package/src/components/editor/plugins/YouTubePlugin/index.ts +41 -0
- package/src/components/editor/themes/editor-theme.ts +113 -0
- package/src/components/editor/themes/theme.css +377 -0
- package/src/components/editor/utils/ai.ts +291 -0
- package/src/components/editor/utils/canUseDOM.ts +12 -0
- package/src/components/editor/utils/editorFormatting.ts +282 -0
- package/src/components/editor/utils/environment.ts +50 -0
- package/src/components/editor/utils/extract-data.ts +166 -0
- package/src/components/editor/utils/getAllLexicalChildren.ts +13 -0
- package/src/components/editor/utils/getDOMRangeRect.ts +27 -0
- package/src/components/editor/utils/getSelectedNode.ts +27 -0
- package/src/components/editor/utils/gif.ts +29 -0
- package/src/components/editor/utils/invariant.ts +15 -0
- package/src/components/editor/utils/setFloatingElemPosition.ts +51 -0
- package/src/components/editor/utils/setFloatingElemPositionForLinkEditor.ts +40 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/getNodePlaceholder.ts +51 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setNodePlaceholderFromSelection.ts +15 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/setPlaceholderOnSelection.ts +114 -0
- package/src/components/editor/utils/setNodePlaceholderFromSelection/styles.css +6 -0
- package/src/components/editor/utils/url.ts +109 -0
- package/src/components/editor/utils/useLayoutEffect.ts +13 -0
- package/src/components/providers/QueryProvider.tsx +15 -0
- package/src/components/providers/SharedHistoryContext.tsx +28 -0
- package/src/components/providers/ToolbarContext.tsx +123 -0
- package/src/components/providers/theme-provider.tsx +11 -0
- package/src/components/theme/ModeToggle.tsx +40 -0
- package/src/components/ui/FileInput.tsx +40 -0
- package/src/components/ui/Input.css +32 -0
- package/src/components/ui/Select.css +42 -0
- package/src/components/ui/Select.tsx +36 -0
- package/src/components/ui/TextInput.tsx +48 -0
- package/src/components/ui/ai/ai-button.tsx +574 -0
- package/src/components/ui/ai/border.tsx +99 -0
- package/src/components/ui/ai/placeholder-input-vanish.tsx +282 -0
- package/src/components/ui/button.tsx +89 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/command.tsx +153 -0
- package/src/components/ui/dialog/Dialog.css +25 -0
- package/src/components/ui/dialog/Dialog.tsx +34 -0
- package/src/components/ui/dialog.tsx +122 -0
- package/src/components/ui/drop-downs/background-color.tsx +183 -0
- package/src/components/ui/drop-downs/block-format.tsx +159 -0
- package/src/components/ui/drop-downs/code.tsx +42 -0
- package/src/components/ui/drop-downs/color.tsx +177 -0
- package/src/components/ui/drop-downs/font-size.tsx +138 -0
- package/src/components/ui/drop-downs/font.tsx +155 -0
- package/src/components/ui/drop-downs/index.tsx +122 -0
- package/src/components/ui/drop-downs/insert-node.tsx +213 -0
- package/src/components/ui/drop-downs/text-align.tsx +123 -0
- package/src/components/ui/drop-downs/text-format.tsx +104 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/equation/EquationEditor.css +38 -0
- package/src/components/ui/equation/EquationEditor.tsx +56 -0
- package/src/components/ui/equation/KatexEquationAlterer.css +41 -0
- package/src/components/ui/equation/KatexEquationAlterer.tsx +83 -0
- package/src/components/ui/equation/KatexRenderer.tsx +66 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.css +64 -0
- package/src/components/ui/excalidraw/ExcalidrawModal.tsx +234 -0
- package/src/components/ui/excalidraw/Modal.css +62 -0
- package/src/components/ui/excalidraw/Modal.tsx +110 -0
- package/src/components/ui/hover-card.tsx +29 -0
- package/src/components/ui/image/error-image.tsx +17 -0
- package/src/components/ui/image/file-upload.tsx +240 -0
- package/src/components/ui/image/image-resizer.tsx +297 -0
- package/src/components/ui/image/image-toolbar.tsx +264 -0
- package/src/components/ui/image/index.tsx +408 -0
- package/src/components/ui/image/lazy-image.tsx +68 -0
- package/src/components/ui/image/lazy-video.tsx +71 -0
- package/src/components/ui/input.tsx +22 -0
- package/src/components/ui/models/custom-dialog.tsx +320 -0
- package/src/components/ui/models/insert-gif.tsx +90 -0
- package/src/components/ui/models/insert-image.tsx +52 -0
- package/src/components/ui/models/insert-poll.tsx +29 -0
- package/src/components/ui/models/insert-table.tsx +62 -0
- package/src/components/ui/models/use-model.tsx +91 -0
- package/src/components/ui/poll/poll-component.tsx +304 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/progress.tsx +28 -0
- package/src/components/ui/scroll-area.tsx +48 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/stepper/step.tsx +179 -0
- package/src/components/ui/stepper/stepper.tsx +89 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/toggle.tsx +71 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/components/ui/write/text-format-floting-toolbar.tsx +346 -0
- package/src/lib/edgestore.ts +9 -0
- package/src/lib/pinecone-client.ts +0 -0
- package/src/lib/utils.ts +6 -0
- package/src/utils/docSerialization.ts +77 -0
- package/src/utils/emoji-list.ts +16615 -0
- package/src/utils/getDOMRangeRect.ts +27 -0
- package/src/utils/getSelectedNode.ts +27 -0
- package/src/utils/getThemeSelector.ts +25 -0
- package/src/utils/isMobileWidth.ts +7 -0
- package/src/utils/joinClasses.ts +13 -0
- package/src/utils/setFloatingElemPosition.ts +74 -0
- package/src/utils/setFloatingElemPositionForLinkEditor.ts +46 -0
- package/src/utils/swipe.ts +127 -0
- package/src/utils/url.ts +38 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,204 @@
|
|
|
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
|
+
import type {
|
|
10
|
+
DOMConversionMap,
|
|
11
|
+
DOMConversionOutput,
|
|
12
|
+
DOMExportOutput,
|
|
13
|
+
EditorConfig,
|
|
14
|
+
LexicalEditor,
|
|
15
|
+
LexicalNode,
|
|
16
|
+
NodeKey,
|
|
17
|
+
SerializedLexicalNode,
|
|
18
|
+
Spread,
|
|
19
|
+
} from 'lexical';
|
|
20
|
+
import type {JSX} from 'react';
|
|
21
|
+
|
|
22
|
+
import {DecoratorNode} from 'lexical';
|
|
23
|
+
import * as React from 'react';
|
|
24
|
+
|
|
25
|
+
type Dimension = number | 'inherit';
|
|
26
|
+
|
|
27
|
+
const ExcalidrawComponent = React.lazy(() => import('./ExcalidrawComponent'));
|
|
28
|
+
|
|
29
|
+
export type SerializedExcalidrawNode = Spread<
|
|
30
|
+
{
|
|
31
|
+
data: string;
|
|
32
|
+
width?: Dimension;
|
|
33
|
+
height?: Dimension;
|
|
34
|
+
},
|
|
35
|
+
SerializedLexicalNode
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
function $convertExcalidrawElement(
|
|
39
|
+
domNode: HTMLElement,
|
|
40
|
+
): DOMConversionOutput | null {
|
|
41
|
+
const excalidrawData = domNode.getAttribute('data-lexical-excalidraw-json');
|
|
42
|
+
const styleAttributes = window.getComputedStyle(domNode);
|
|
43
|
+
const heightStr = styleAttributes.getPropertyValue('height');
|
|
44
|
+
const widthStr = styleAttributes.getPropertyValue('width');
|
|
45
|
+
const height =
|
|
46
|
+
!heightStr || heightStr === 'inherit' ? 'inherit' : parseInt(heightStr, 10);
|
|
47
|
+
const width =
|
|
48
|
+
!widthStr || widthStr === 'inherit' ? 'inherit' : parseInt(widthStr, 10);
|
|
49
|
+
|
|
50
|
+
if (excalidrawData) {
|
|
51
|
+
const node = $createExcalidrawNode(excalidrawData, width, height);
|
|
52
|
+
return {
|
|
53
|
+
node,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export class ExcalidrawNode extends DecoratorNode<JSX.Element> {
|
|
60
|
+
__data: string;
|
|
61
|
+
__width: Dimension;
|
|
62
|
+
__height: Dimension;
|
|
63
|
+
|
|
64
|
+
static getType(): string {
|
|
65
|
+
return 'excalidraw';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static clone(node: ExcalidrawNode): ExcalidrawNode {
|
|
69
|
+
return new ExcalidrawNode(
|
|
70
|
+
node.__data,
|
|
71
|
+
node.__width,
|
|
72
|
+
node.__height,
|
|
73
|
+
node.__key,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static importJSON(serializedNode: SerializedExcalidrawNode): ExcalidrawNode {
|
|
78
|
+
return new ExcalidrawNode(
|
|
79
|
+
serializedNode.data,
|
|
80
|
+
serializedNode.width ?? 'inherit',
|
|
81
|
+
serializedNode.height ?? 'inherit',
|
|
82
|
+
).updateFromJSON(serializedNode);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exportJSON(): SerializedExcalidrawNode {
|
|
86
|
+
return {
|
|
87
|
+
...super.exportJSON(),
|
|
88
|
+
data: this.__data,
|
|
89
|
+
height: this.__height === 'inherit' ? undefined : this.__height,
|
|
90
|
+
width: this.__width === 'inherit' ? undefined : this.__width,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
constructor(
|
|
95
|
+
data = '[]',
|
|
96
|
+
width: Dimension = 'inherit',
|
|
97
|
+
height: Dimension = 'inherit',
|
|
98
|
+
key?: NodeKey,
|
|
99
|
+
) {
|
|
100
|
+
super(key);
|
|
101
|
+
this.__data = data;
|
|
102
|
+
this.__width = width;
|
|
103
|
+
this.__height = height;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// View
|
|
107
|
+
createDOM(config: EditorConfig): HTMLElement {
|
|
108
|
+
const span = document.createElement('span');
|
|
109
|
+
const theme = config.theme;
|
|
110
|
+
const className = theme.image;
|
|
111
|
+
if (className !== undefined) {
|
|
112
|
+
span.className = className;
|
|
113
|
+
}
|
|
114
|
+
return span;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
updateDOM(): false {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static importDOM(): DOMConversionMap<HTMLSpanElement> | null {
|
|
122
|
+
return {
|
|
123
|
+
span: (domNode: HTMLSpanElement) => {
|
|
124
|
+
if (!domNode.hasAttribute('data-lexical-excalidraw-json')) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
conversion: $convertExcalidrawElement,
|
|
129
|
+
priority: 1,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exportDOM(editor: LexicalEditor): DOMExportOutput {
|
|
136
|
+
const element = document.createElement('span');
|
|
137
|
+
|
|
138
|
+
element.style.display = 'inline-block';
|
|
139
|
+
|
|
140
|
+
const content = editor.getElementByKey(this.getKey());
|
|
141
|
+
if (content !== null) {
|
|
142
|
+
const svg = content.querySelector('svg');
|
|
143
|
+
if (svg !== null) {
|
|
144
|
+
element.innerHTML = svg.outerHTML;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
element.style.width =
|
|
149
|
+
this.__width === 'inherit' ? 'inherit' : `${this.__width}px`;
|
|
150
|
+
element.style.height =
|
|
151
|
+
this.__height === 'inherit' ? 'inherit' : `${this.__height}px`;
|
|
152
|
+
|
|
153
|
+
element.setAttribute('data-lexical-excalidraw-json', this.__data);
|
|
154
|
+
return {element};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setData(data: string): void {
|
|
158
|
+
const self = this.getWritable();
|
|
159
|
+
self.__data = data;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getWidth(): Dimension {
|
|
163
|
+
return this.getLatest().__width;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
setWidth(width: Dimension): void {
|
|
167
|
+
const self = this.getWritable();
|
|
168
|
+
self.__width = width;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getHeight(): Dimension {
|
|
172
|
+
return this.getLatest().__height;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
setHeight(height: Dimension): void {
|
|
176
|
+
const self = this.getWritable();
|
|
177
|
+
self.__height = height;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
decorate(editor: LexicalEditor, config: EditorConfig): JSX.Element {
|
|
181
|
+
return (
|
|
182
|
+
<ExcalidrawComponent
|
|
183
|
+
nodeKey={this.getKey()}
|
|
184
|
+
data={this.__data}
|
|
185
|
+
width={this.__width}
|
|
186
|
+
height={this.__height}
|
|
187
|
+
/>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function $createExcalidrawNode(
|
|
193
|
+
data: string = '[]',
|
|
194
|
+
width: Dimension = 'inherit',
|
|
195
|
+
height: Dimension = 'inherit',
|
|
196
|
+
): ExcalidrawNode {
|
|
197
|
+
return new ExcalidrawNode(data, width, height);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export function $isExcalidrawNode(
|
|
201
|
+
node: LexicalNode | null | undefined,
|
|
202
|
+
): node is ExcalidrawNode {
|
|
203
|
+
return node instanceof ExcalidrawNode;
|
|
204
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
import type {
|
|
10
|
+
EditorConfig,
|
|
11
|
+
ElementFormatType,
|
|
12
|
+
LexicalEditor,
|
|
13
|
+
LexicalNode,
|
|
14
|
+
NodeKey,
|
|
15
|
+
Spread,
|
|
16
|
+
} from 'lexical';
|
|
17
|
+
import type {JSX} from 'react';
|
|
18
|
+
|
|
19
|
+
import {BlockWithAlignableContents} from '@lexical/react/LexicalBlockWithAlignableContents';
|
|
20
|
+
import {
|
|
21
|
+
DecoratorBlockNode,
|
|
22
|
+
SerializedDecoratorBlockNode,
|
|
23
|
+
} from '@lexical/react/LexicalDecoratorBlockNode';
|
|
24
|
+
import * as React from 'react';
|
|
25
|
+
|
|
26
|
+
type FigmaComponentProps = Readonly<{
|
|
27
|
+
className: Readonly<{
|
|
28
|
+
base: string;
|
|
29
|
+
focus: string;
|
|
30
|
+
}>;
|
|
31
|
+
format: ElementFormatType | null;
|
|
32
|
+
nodeKey: NodeKey;
|
|
33
|
+
documentID: string;
|
|
34
|
+
}>;
|
|
35
|
+
|
|
36
|
+
function FigmaComponent({
|
|
37
|
+
className,
|
|
38
|
+
format,
|
|
39
|
+
nodeKey,
|
|
40
|
+
documentID,
|
|
41
|
+
}: FigmaComponentProps) {
|
|
42
|
+
return (
|
|
43
|
+
<BlockWithAlignableContents
|
|
44
|
+
className={className}
|
|
45
|
+
format={format}
|
|
46
|
+
nodeKey={nodeKey}>
|
|
47
|
+
<iframe
|
|
48
|
+
width="560"
|
|
49
|
+
height="315"
|
|
50
|
+
src={`https://www.figma.com/embed?embed_host=lexical&url=\
|
|
51
|
+
https://www.figma.com/file/${documentID}`}
|
|
52
|
+
allowFullScreen={true}
|
|
53
|
+
/>
|
|
54
|
+
</BlockWithAlignableContents>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type SerializedFigmaNode = Spread<
|
|
59
|
+
{
|
|
60
|
+
documentID: string;
|
|
61
|
+
},
|
|
62
|
+
SerializedDecoratorBlockNode
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
export class FigmaNode extends DecoratorBlockNode {
|
|
66
|
+
__id: string;
|
|
67
|
+
|
|
68
|
+
static getType(): string {
|
|
69
|
+
return 'figma';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static clone(node: FigmaNode): FigmaNode {
|
|
73
|
+
return new FigmaNode(node.__id, node.__format, node.__key);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static importJSON(serializedNode: SerializedFigmaNode): FigmaNode {
|
|
77
|
+
return $createFigmaNode(serializedNode.documentID).updateFromJSON(
|
|
78
|
+
serializedNode,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exportJSON(): SerializedFigmaNode {
|
|
83
|
+
return {
|
|
84
|
+
...super.exportJSON(),
|
|
85
|
+
documentID: this.__id,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor(id: string, format?: ElementFormatType, key?: NodeKey) {
|
|
90
|
+
super(format, key);
|
|
91
|
+
this.__id = id;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
updateDOM(): false {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getId(): string {
|
|
99
|
+
return this.__id;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
getTextContent(
|
|
103
|
+
_includeInert?: boolean | undefined,
|
|
104
|
+
_includeDirectionless?: false | undefined,
|
|
105
|
+
): string {
|
|
106
|
+
return `https://www.figma.com/file/${this.__id}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
decorate(_editor: LexicalEditor, config: EditorConfig): JSX.Element {
|
|
110
|
+
const embedBlockTheme = config.theme.embedBlock || {};
|
|
111
|
+
const className = {
|
|
112
|
+
base: embedBlockTheme.base || '',
|
|
113
|
+
focus: embedBlockTheme.focus || '',
|
|
114
|
+
};
|
|
115
|
+
return (
|
|
116
|
+
<FigmaComponent
|
|
117
|
+
className={className}
|
|
118
|
+
format={this.__format}
|
|
119
|
+
nodeKey={this.getKey()}
|
|
120
|
+
documentID={this.__id}
|
|
121
|
+
/>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function $createFigmaNode(documentID: string): FigmaNode {
|
|
127
|
+
return new FigmaNode(documentID);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function $isFigmaNode(
|
|
131
|
+
node: FigmaNode | LexicalNode | null | undefined,
|
|
132
|
+
): node is FigmaNode {
|
|
133
|
+
return node instanceof FigmaNode;
|
|
134
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { $getNodeByKey, LexicalEditor, NodeKey } from "lexical";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
5
|
+
import { cva } from "class-variance-authority";
|
|
6
|
+
import { ContentEditable } from "@lexical/react/LexicalContentEditable";
|
|
7
|
+
import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
|
|
8
|
+
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
|
|
9
|
+
import { LexicalNestedComposer } from "@lexical/react/LexicalNestedComposer";
|
|
10
|
+
import { PlainTextPlugin } from "@lexical/react/LexicalPlainTextPlugin";
|
|
11
|
+
import { $isHintNode, HintType } from ".";
|
|
12
|
+
|
|
13
|
+
const hintVariants = cva(
|
|
14
|
+
"hint p-4 max-sm:p-2 transition-colors my-2 flex flex-row max-sm:flex-col items-start relative justify-between rounded-md straight-corners:rounded-none w-full text-destructive-foreground shadow-xl mx-auto max-w-3xl",
|
|
15
|
+
{
|
|
16
|
+
variants: {
|
|
17
|
+
variant: {
|
|
18
|
+
default:
|
|
19
|
+
"border border-border/20 dark:bg-black bg-white text-foreground",
|
|
20
|
+
success:
|
|
21
|
+
"dark:bg-green-500/20 bg-green-500/70 dark:shadow-green-800/10 shadow-green-500/30 border-green-500/40 decoration-primary/60",
|
|
22
|
+
|
|
23
|
+
error:
|
|
24
|
+
"destructive border-destructive dark:shadow-red-800/20 shadow-red-500/30 bg-destructive ",
|
|
25
|
+
warning:
|
|
26
|
+
"bg-yellow-500/50 dark:shadow-yellow-500/10 shadow-yellow-500/20 border-yellow-500/40",
|
|
27
|
+
info: "bg-blue-500/50 shadow-blue-500/10 bg-blue-700/70 shadow-blue-700/20 border-blue-500/40",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
variant: "default",
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
export default function HintComponent({
|
|
38
|
+
type,
|
|
39
|
+
captionEditor,
|
|
40
|
+
nodeKey,
|
|
41
|
+
}: {
|
|
42
|
+
type: HintType;
|
|
43
|
+
captionEditor: LexicalEditor;
|
|
44
|
+
nodeKey: NodeKey;
|
|
45
|
+
}) {
|
|
46
|
+
const [editor] = useLexicalComposerContext();
|
|
47
|
+
|
|
48
|
+
const variantMap: any = {
|
|
49
|
+
hint: "success",
|
|
50
|
+
warning: "warning",
|
|
51
|
+
info: "info",
|
|
52
|
+
error: "error",
|
|
53
|
+
success: "success",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const variant = variantMap[type] || "default";
|
|
57
|
+
|
|
58
|
+
const variantOrder: HintType[] = [
|
|
59
|
+
"success",
|
|
60
|
+
"warning",
|
|
61
|
+
"info",
|
|
62
|
+
"error",
|
|
63
|
+
"hint",
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
function handleIcon(type: HintType) {
|
|
67
|
+
switch (type) {
|
|
68
|
+
case "hint":
|
|
69
|
+
return (
|
|
70
|
+
<svg
|
|
71
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
72
|
+
width="1.5em"
|
|
73
|
+
height="1.5em"
|
|
74
|
+
viewBox="0 0 36 36"
|
|
75
|
+
>
|
|
76
|
+
<path
|
|
77
|
+
fill="currentColor"
|
|
78
|
+
d="M18 2a16 16 0 1 0 16 16A16 16 0 0 0 18 2m0 30a14 14 0 1 1 14-14a14 14 0 0 1-14 14"
|
|
79
|
+
className="clr-i-outline clr-i-outline-path-1"
|
|
80
|
+
></path>
|
|
81
|
+
<path
|
|
82
|
+
fill="currentColor"
|
|
83
|
+
d="M28 12.1a1 1 0 0 0-1.41 0l-11.1 11.05l-6-6A1 1 0 0 0 8 18.53L15.49 26L28 13.52a1 1 0 0 0 0-1.42"
|
|
84
|
+
className="clr-i-outline clr-i-outline-path-2"
|
|
85
|
+
></path>
|
|
86
|
+
<path fill="none" d="M0 0h36v36H0z"></path>
|
|
87
|
+
</svg>
|
|
88
|
+
);
|
|
89
|
+
case "warning":
|
|
90
|
+
return (
|
|
91
|
+
<svg
|
|
92
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
93
|
+
width="1.5em"
|
|
94
|
+
height="1.5em"
|
|
95
|
+
viewBox="0 0 24 24"
|
|
96
|
+
>
|
|
97
|
+
<path
|
|
98
|
+
fill="currentColor"
|
|
99
|
+
d="M4.126 20q-.234 0-.414-.111t-.28-.293q-.108-.179-.12-.387q-.01-.209.118-.421L11.3 5.212q.128-.212.308-.308T12 4.808t.391.096t.308.308l7.871 13.576q.128.212.117.42q-.01.21-.12.388q-.1.182-.28.293t-.413.111zm.324-1h15.1L12 6zM12 17.616q.262 0 .439-.177t.176-.439t-.177-.438t-.438-.178t-.438.177t-.177.439t.177.439t.438.177m0-2.231q.214 0 .357-.144t.143-.356v-4q0-.213-.144-.357t-.357-.143t-.356.143t-.143.357v4q0 .212.144.356t.357.144M12 12.5"
|
|
100
|
+
></path>
|
|
101
|
+
</svg>
|
|
102
|
+
);
|
|
103
|
+
case "info":
|
|
104
|
+
return (
|
|
105
|
+
<svg
|
|
106
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
107
|
+
width="1.5em"
|
|
108
|
+
height="1.5em"
|
|
109
|
+
viewBox="0 0 24 24"
|
|
110
|
+
>
|
|
111
|
+
<g fill="none" stroke="currentColor" strokeLinejoin="round">
|
|
112
|
+
<circle
|
|
113
|
+
cx="12"
|
|
114
|
+
cy="12"
|
|
115
|
+
r="9"
|
|
116
|
+
strokeLinecap="round"
|
|
117
|
+
strokeWidth="1.5"
|
|
118
|
+
></circle>
|
|
119
|
+
<path strokeWidth="2.25" d="M12 8h.01v.01H12z"></path>
|
|
120
|
+
<path strokeLinecap="round" strokeWidth="1.5" d="M12 12v4"></path>
|
|
121
|
+
</g>
|
|
122
|
+
</svg>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
case "error":
|
|
126
|
+
return (
|
|
127
|
+
<svg
|
|
128
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
129
|
+
width="1.5em"
|
|
130
|
+
height="1.5em"
|
|
131
|
+
viewBox="0 0 512 512"
|
|
132
|
+
>
|
|
133
|
+
<path
|
|
134
|
+
fill="currentColor"
|
|
135
|
+
fillRule="evenodd"
|
|
136
|
+
d="M256 42.667c117.803 0 213.334 95.53 213.334 213.333S373.803 469.334 256 469.334S42.667 373.803 42.667 256S138.197 42.667 256 42.667m0 42.667c-94.1 0-170.666 76.565-170.666 170.666c0 94.102 76.565 170.667 170.666 170.667c94.102 0 170.667-76.565 170.667-170.667c0-94.101-76.565-170.666-170.667-170.666m48.918 91.584l30.165 30.165L286.166 256l48.917 48.918l-30.165 30.165L256 286.166l-48.917 48.917l-30.165-30.165L225.835 256l-48.917-48.917l30.165-30.165L256 225.835z"
|
|
137
|
+
></path>
|
|
138
|
+
</svg>
|
|
139
|
+
);
|
|
140
|
+
case "success":
|
|
141
|
+
return (
|
|
142
|
+
<svg
|
|
143
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
144
|
+
width="1.5em"
|
|
145
|
+
height="1.5em"
|
|
146
|
+
viewBox="0 0 36 36"
|
|
147
|
+
>
|
|
148
|
+
<path
|
|
149
|
+
fill="currentColor"
|
|
150
|
+
d="M18 2a16 16 0 1 0 16 16A16 16 0 0 0 18 2m0 30a14 14 0 1 1 14-14a14 14 0 0 1-14 14"
|
|
151
|
+
className="clr-i-outline clr-i-outline-path-1"
|
|
152
|
+
></path>
|
|
153
|
+
<path
|
|
154
|
+
fill="currentColor"
|
|
155
|
+
d="M28 12.1a1 1 0 0 0-1.41 0l-11.1 11.05l-6-6A1 1 0 0 0 8 18.53L15.49 26L28 13.52a1 1 0 0 0 0-1.42"
|
|
156
|
+
className="clr-i-outline clr-i-outline-path-2"
|
|
157
|
+
></path>
|
|
158
|
+
<path fill="none" d="M0 0h36v36H0z"></path>
|
|
159
|
+
</svg>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function handleVariantChange() {
|
|
165
|
+
editor.update(() => {
|
|
166
|
+
const node = $getNodeByKey(nodeKey);
|
|
167
|
+
if ($isHintNode(node)) {
|
|
168
|
+
const currentVariant = node.__variant;
|
|
169
|
+
const currentIndex = variantOrder.indexOf(currentVariant);
|
|
170
|
+
const nextIndex = (currentIndex + 1) % variantOrder.length;
|
|
171
|
+
const nextVariant = variantOrder[nextIndex];
|
|
172
|
+
|
|
173
|
+
node.setVariant(nextVariant);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div className={hintVariants({ variant })}>
|
|
182
|
+
<button
|
|
183
|
+
type="button"
|
|
184
|
+
disabled={!editor.isEditable()}
|
|
185
|
+
onClick={handleVariantChange}
|
|
186
|
+
className="cursor-pointer max-sm:mb-1 ml-2"
|
|
187
|
+
>
|
|
188
|
+
{handleIcon(variant)}
|
|
189
|
+
</button>
|
|
190
|
+
<LexicalNestedComposer initialEditor={captionEditor}>
|
|
191
|
+
<HistoryPlugin />
|
|
192
|
+
<PlainTextPlugin
|
|
193
|
+
contentEditable={
|
|
194
|
+
<ContentEditable
|
|
195
|
+
className="
|
|
196
|
+
flex-1 ml-3
|
|
197
|
+
border-0 resize-none cursor-text
|
|
198
|
+
block relative outline-none select-text
|
|
199
|
+
whitespace-pre-wrap break-words
|
|
200
|
+
"
|
|
201
|
+
aria-placeholder={"Write hint caption"}
|
|
202
|
+
contentEditable={editor.isEditable()}
|
|
203
|
+
aria-disabled={true}
|
|
204
|
+
placeholder={
|
|
205
|
+
<div
|
|
206
|
+
className="
|
|
207
|
+
text-base text-[#999] overflow-hidden absolute top-[17px] left-[55px]
|
|
208
|
+
select-none text-nowrap inline-block text-ellipsis pointer-events-none
|
|
209
|
+
"
|
|
210
|
+
>
|
|
211
|
+
Write your note
|
|
212
|
+
</div>
|
|
213
|
+
}
|
|
214
|
+
/>
|
|
215
|
+
}
|
|
216
|
+
ErrorBoundary={LexicalErrorBoundary}
|
|
217
|
+
/>
|
|
218
|
+
</LexicalNestedComposer>
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
}
|