5htp-core 0.4.9-96 → 0.4.9-98

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.
@@ -7,260 +7,276 @@
7
7
  */
8
8
 
9
9
  import type {
10
- DOMConversionMap,
11
- DOMConversionOutput,
12
- DOMExportOutput,
13
- EditorConfig,
14
- LexicalEditor,
15
- LexicalNode,
16
- NodeKey,
17
- SerializedEditor,
18
- SerializedLexicalNode,
19
- Spread,
10
+ DOMConversionMap,
11
+ DOMConversionOutput,
12
+ DOMExportOutput,
13
+ EditorConfig,
14
+ LexicalEditor,
15
+ LexicalNode,
16
+ NodeKey,
17
+ SerializedEditor,
18
+ SerializedLexicalNode,
19
+ Spread,
20
20
  } from 'lexical';
21
21
 
22
- import {$applyNodeReplacement, createEditor, DecoratorNode} from 'lexical';
22
+ import { $generateHtmlFromNodes } from '@lexical/html';
23
+
24
+ import { $applyNodeReplacement, createEditor, DecoratorNode } from 'lexical';
23
25
  import * as React from 'react';
24
- import {Suspense} from 'react';
26
+ import { Suspense } from 'react';
25
27
 
26
28
  const ImageComponent = React.lazy(() => import('./ImageComponent'));
27
29
 
28
30
  export interface ImagePayload {
29
- altText: string;
30
- caption?: LexicalEditor;
31
- height?: number;
32
- key?: NodeKey;
33
- maxWidth?: number;
34
- showCaption?: boolean;
35
- src: string;
36
- width?: number;
37
- captionsEnabled?: boolean;
31
+ altText: string;
32
+ caption?: LexicalEditor;
33
+ height?: number;
34
+ key?: NodeKey;
35
+ maxWidth?: number;
36
+ showCaption?: boolean;
37
+ src: string;
38
+ width?: number;
39
+ captionsEnabled?: boolean;
38
40
  }
39
41
 
40
42
  function isGoogleDocCheckboxImg(img: HTMLImageElement): boolean {
41
- return (
42
- img.parentElement != null &&
43
- img.parentElement.tagName === 'LI' &&
44
- img.previousSibling === null &&
45
- img.getAttribute('aria-roledescription') === 'checkbox'
46
- );
43
+ return (
44
+ img.parentElement != null &&
45
+ img.parentElement.tagName === 'LI' &&
46
+ img.previousSibling === null &&
47
+ img.getAttribute('aria-roledescription') === 'checkbox'
48
+ );
47
49
  }
48
50
 
49
51
  function $convertImageElement(domNode: Node): null | DOMConversionOutput {
50
- const img = domNode as HTMLImageElement;
51
- if (img.src.startsWith('file:///') || isGoogleDocCheckboxImg(img)) {
52
- return null;
53
- }
54
- const {alt: altText, src, width, height} = img;
55
- const node = $createImageNode({altText, height, src, width});
56
- return {node};
52
+ const img = domNode as HTMLImageElement;
53
+ if (img.src.startsWith('file:///') || isGoogleDocCheckboxImg(img)) {
54
+ return null;
55
+ }
56
+ const { alt: altText, src, width, height } = img;
57
+ const node = $createImageNode({ altText, height, src, width });
58
+ return { node };
57
59
  }
58
60
 
59
61
  export type SerializedImageNode = Spread<
60
- {
61
- altText: string;
62
- caption: SerializedEditor;
63
- height?: number;
64
- maxWidth: number;
65
- showCaption: boolean;
66
- src: string;
67
- width?: number;
68
- },
69
- SerializedLexicalNode
62
+ {
63
+ altText: string;
64
+ caption: SerializedEditor;
65
+ height?: number;
66
+ maxWidth: number;
67
+ showCaption: boolean;
68
+ src: string;
69
+ width?: number;
70
+ },
71
+ SerializedLexicalNode
70
72
  >;
71
73
 
72
- export class ImageNode extends DecoratorNode<JSX.Element> {
73
- __src: string;
74
- __altText: string;
75
- __width: 'inherit' | number;
76
- __height: 'inherit' | number;
77
- __maxWidth: number;
78
- __showCaption: boolean;
79
- __caption: LexicalEditor;
80
- // Captions cannot yet be used within editor cells
81
- __captionsEnabled: boolean;
74
+ export class ImageNode extends DecoratorNode<React.JSX.Element> {
75
+ __src: string;
76
+ __altText: string;
77
+ __width: 'inherit' | number;
78
+ __height: 'inherit' | number;
79
+ __maxWidth: number;
80
+ __showCaption: boolean;
81
+ __caption: LexicalEditor;
82
+ // Captions cannot yet be used within editor cells
83
+ __captionsEnabled: boolean;
82
84
 
83
- static getType(): string {
84
- return 'image';
85
- }
85
+ static getType(): string {
86
+ return 'image';
87
+ }
86
88
 
87
- static clone(node: ImageNode): ImageNode {
88
- return new ImageNode(
89
- node.__src,
90
- node.__altText,
91
- node.__maxWidth,
92
- node.__width,
93
- node.__height,
94
- node.__showCaption,
95
- node.__caption,
96
- node.__captionsEnabled,
97
- node.__key,
98
- );
99
- }
89
+ static clone(node: ImageNode): ImageNode {
90
+ return new ImageNode(
91
+ node.__src,
92
+ node.__altText,
93
+ node.__maxWidth,
94
+ node.__width,
95
+ node.__height,
96
+ node.__showCaption,
97
+ node.__caption,
98
+ node.__captionsEnabled,
99
+ node.__key,
100
+ );
101
+ }
100
102
 
101
- static importJSON(serializedNode: SerializedImageNode): ImageNode {
102
- const {altText, height, width, maxWidth, caption, src, showCaption} =
103
- serializedNode;
104
- const node = $createImageNode({
105
- altText,
106
- height,
107
- maxWidth,
108
- showCaption,
109
- src,
110
- width,
111
- });
112
- const nestedEditor = node.__caption;
113
- const editorState = nestedEditor.parseEditorState(caption.editorState);
114
- if (!editorState.isEmpty()) {
115
- nestedEditor.setEditorState(editorState);
103
+ static importJSON(serializedNode: SerializedImageNode): ImageNode {
104
+ const { altText, height, width, maxWidth, caption, src, showCaption } =
105
+ serializedNode;
106
+ const node = $createImageNode({
107
+ altText,
108
+ height,
109
+ maxWidth,
110
+ showCaption,
111
+ src,
112
+ width,
113
+ });
114
+ const nestedEditor = node.__caption;
115
+ const editorState = nestedEditor.parseEditorState(caption.editorState);
116
+ if (!editorState.isEmpty()) {
117
+ nestedEditor.setEditorState(editorState);
118
+ }
119
+ return node;
116
120
  }
117
- return node;
118
- }
119
121
 
120
- exportDOM(): DOMExportOutput {
121
- const element = document.createElement('img');
122
- element.setAttribute('src', this.__src);
123
- element.setAttribute('alt', this.__altText);
124
- element.setAttribute('width', this.__width.toString());
125
- element.setAttribute('height', this.__height.toString());
126
- return {element};
127
- }
122
+ exportDOM(): DOMExportOutput {
123
+ const figure = document.createElement('figure');
128
124
 
129
- static importDOM(): DOMConversionMap | null {
130
- return {
131
- img: (node: Node) => ({
132
- conversion: $convertImageElement,
133
- priority: 0,
134
- }),
135
- };
136
- }
125
+ const img = document.createElement('img');
126
+ figure.appendChild(img);
127
+ img.setAttribute('src', this.__src);
128
+ img.setAttribute('alt', this.__altText);
129
+ img.setAttribute('width', this.__width.toString());
130
+ img.setAttribute('height', this.__height.toString());
137
131
 
138
- constructor(
139
- src: string,
140
- altText: string,
141
- maxWidth: number,
142
- width?: 'inherit' | number,
143
- height?: 'inherit' | number,
144
- showCaption?: boolean,
145
- caption?: LexicalEditor,
146
- captionsEnabled?: boolean,
147
- key?: NodeKey,
148
- ) {
149
- super(key);
150
- this.__src = src;
151
- this.__altText = altText;
152
- this.__maxWidth = maxWidth;
153
- this.__width = width || 'inherit';
154
- this.__height = height || 'inherit';
155
- this.__showCaption = showCaption || false;
156
- this.__caption =
157
- caption ||
158
- createEditor({
159
- nodes: [],
160
- });
161
- this.__captionsEnabled = captionsEnabled || captionsEnabled === undefined;
162
- }
132
+ // Caption
133
+ if (this.__showCaption) {
134
+ const figcaption = document.createElement('figcaption');
135
+ const captionHtml = this.__caption.getEditorState().read(() => {
136
+ return $generateHtmlFromNodes(this.__caption, null);
137
+ });
138
+ figcaption.innerHTML = captionHtml;
139
+ figure.appendChild(figcaption);
140
+ }
163
141
 
164
- exportJSON(): SerializedImageNode {
165
- return {
166
- altText: this.getAltText(),
167
- caption: this.__caption.toJSON(),
168
- height: this.__height === 'inherit' ? 0 : this.__height,
169
- maxWidth: this.__maxWidth,
170
- showCaption: this.__showCaption,
171
- src: this.getSrc(),
172
- type: 'image',
173
- version: 1,
174
- width: this.__width === 'inherit' ? 0 : this.__width,
175
- };
176
- }
142
+ return { element: figure };
143
+ }
177
144
 
178
- setWidthAndHeight(
179
- width: 'inherit' | number,
180
- height: 'inherit' | number,
181
- ): void {
182
- const writable = this.getWritable();
183
- writable.__width = width;
184
- writable.__height = height;
185
- }
145
+ static importDOM(): DOMConversionMap | null {
146
+ return {
147
+ img: (node: Node) => ({
148
+ conversion: $convertImageElement,
149
+ priority: 0,
150
+ }),
151
+ };
152
+ }
186
153
 
187
- setShowCaption(showCaption: boolean): void {
188
- const writable = this.getWritable();
189
- writable.__showCaption = showCaption;
190
- }
154
+ constructor(
155
+ src: string,
156
+ altText: string,
157
+ maxWidth: number,
158
+ width?: 'inherit' | number,
159
+ height?: 'inherit' | number,
160
+ showCaption?: boolean,
161
+ caption?: LexicalEditor,
162
+ captionsEnabled?: boolean,
163
+ key?: NodeKey,
164
+ ) {
165
+ super(key);
166
+ this.__src = src;
167
+ this.__altText = altText;
168
+ this.__maxWidth = maxWidth;
169
+ this.__width = width || 'inherit';
170
+ this.__height = height || 'inherit';
171
+ this.__showCaption = showCaption || false;
172
+ this.__caption =
173
+ caption ||
174
+ createEditor({
175
+ nodes: [],
176
+ });
177
+ this.__captionsEnabled = captionsEnabled || captionsEnabled === undefined;
178
+ }
191
179
 
192
- // View
180
+ exportJSON(): SerializedImageNode {
181
+ return {
182
+ altText: this.getAltText(),
183
+ caption: this.__caption.toJSON(),
184
+ height: this.__height === 'inherit' ? 0 : this.__height,
185
+ maxWidth: this.__maxWidth,
186
+ showCaption: this.__showCaption,
187
+ src: this.getSrc(),
188
+ type: 'image',
189
+ version: 1,
190
+ width: this.__width === 'inherit' ? 0 : this.__width,
191
+ };
192
+ }
193
193
 
194
- createDOM(config: EditorConfig): HTMLElement {
195
- const span = document.createElement('span');
196
- const theme = config.theme;
197
- const className = theme.image;
198
- if (className !== undefined) {
199
- span.className = className;
194
+ setWidthAndHeight(
195
+ width: 'inherit' | number,
196
+ height: 'inherit' | number,
197
+ ): void {
198
+ const writable = this.getWritable();
199
+ writable.__width = width;
200
+ writable.__height = height;
200
201
  }
201
- return span;
202
- }
203
202
 
204
- updateDOM(): false {
205
- return false;
206
- }
203
+ setShowCaption(showCaption: boolean): void {
204
+ const writable = this.getWritable();
205
+ writable.__showCaption = showCaption;
206
+ }
207
207
 
208
- getSrc(): string {
209
- return this.__src;
210
- }
208
+ // View
211
209
 
212
- getAltText(): string {
213
- return this.__altText;
214
- }
210
+ createDOM(config: EditorConfig): HTMLElement {
211
+ const span = document.createElement('span');
212
+ const theme = config.theme;
213
+ const className = theme.image;
214
+ if (className !== undefined) {
215
+ span.className = className;
216
+ }
217
+ return span;
218
+ }
215
219
 
216
- decorate(): JSX.Element {
217
- return (
218
- <Suspense fallback={null}>
219
- <ImageComponent
220
- src={this.__src}
221
- altText={this.__altText}
222
- width={this.__width}
223
- height={this.__height}
224
- maxWidth={this.__maxWidth}
225
- nodeKey={this.getKey()}
226
- showCaption={this.__showCaption}
227
- caption={this.__caption}
228
- captionsEnabled={this.__captionsEnabled}
229
- resizable={true}
230
- />
231
- </Suspense>
232
- );
233
- }
220
+ updateDOM(): false {
221
+ return false;
222
+ }
223
+
224
+ getSrc(): string {
225
+ return this.__src;
226
+ }
227
+
228
+ getAltText(): string {
229
+ return this.__altText;
230
+ }
231
+
232
+ decorate(): React.JSX.Element {
233
+ return (
234
+ <Suspense fallback={null}>
235
+ <ImageComponent
236
+ src={this.__src}
237
+ altText={this.__altText}
238
+ width={this.__width}
239
+ height={this.__height}
240
+ maxWidth={this.__maxWidth}
241
+ nodeKey={this.getKey()}
242
+ showCaption={this.__showCaption}
243
+ caption={this.__caption}
244
+ captionsEnabled={this.__captionsEnabled}
245
+ resizable={true}
246
+ />
247
+ </Suspense>
248
+ );
249
+ }
234
250
  }
235
251
 
236
252
  export function $createImageNode({
237
- altText,
238
- height,
239
- maxWidth = 500,
240
- captionsEnabled,
241
- src,
242
- width,
243
- showCaption,
244
- caption,
245
- key,
253
+ altText,
254
+ height,
255
+ maxWidth = 500,
256
+ captionsEnabled,
257
+ src,
258
+ width,
259
+ showCaption,
260
+ caption,
261
+ key,
246
262
  }: ImagePayload): ImageNode {
247
- return $applyNodeReplacement(
248
- new ImageNode(
249
- src,
250
- altText,
251
- maxWidth,
252
- width,
253
- height,
254
- showCaption,
255
- caption,
256
- captionsEnabled,
257
- key,
258
- ),
259
- );
263
+ return $applyNodeReplacement(
264
+ new ImageNode(
265
+ src,
266
+ altText,
267
+ maxWidth,
268
+ width,
269
+ height,
270
+ showCaption,
271
+ caption,
272
+ captionsEnabled,
273
+ key,
274
+ ),
275
+ );
260
276
  }
261
277
 
262
278
  export function $isImageNode(
263
- node: LexicalNode | null | undefined,
279
+ node: LexicalNode | null | undefined,
264
280
  ): node is ImageNode {
265
- return node instanceof ImageNode;
281
+ return node instanceof ImageNode;
266
282
  }
@@ -56,7 +56,7 @@ function PollOptionComponent({
56
56
  cb: (pollNode: PollNode) => void,
57
57
  onSelect?: () => void,
58
58
  ) => void;
59
- }): JSX.Element {
59
+ }): React.JSX.Element {
60
60
 
61
61
  const { clientID } = useCollaborationContext();
62
62
  const checkboxRef = useRef(null);
@@ -93,23 +93,19 @@ function PollOptionComponent({
93
93
  {votes > 0 && (votes === 1 ? '1 vote' : `${votes} votes`)}
94
94
  </span>
95
95
  <Input
96
+ wrapper={false}
96
97
  value={text}
97
- onChange={(e) => {
98
- const target = e.target;
99
- const value = target.value;
100
- const selectionStart = target.selectionStart;
101
- const selectionEnd = target.selectionEnd;
98
+ onChange={(value) => {
102
99
  withPollNode(
103
100
  (node) => {
104
101
  node.setOptionText(option, value);
105
102
  },
106
103
  () => {
107
- target.selectionStart = selectionStart;
108
- target.selectionEnd = selectionEnd;
104
+
109
105
  },
110
106
  );
111
107
  }}
112
- placeholder={`Option ${index + 1}`}
108
+ title={`Option ${index + 1}`}
113
109
  className="col-1"
114
110
  />
115
111
  <Button
@@ -133,7 +129,7 @@ export default function PollComponent({
133
129
  nodeKey: NodeKey;
134
130
  options: Options;
135
131
  question: string;
136
- }): JSX.Element {
132
+ }): React.JSX.Element {
137
133
 
138
134
  const [editor] = useLexicalComposerContext();
139
135
  const totalVotes = useMemo(() => getTotalVotes(options), [options]);
@@ -74,7 +74,7 @@ function $convertPollElement(domNode: HTMLElement): DOMConversionOutput | null {
74
74
  return null;
75
75
  }
76
76
 
77
- export class PollNode extends DecoratorNode<JSX.Element> {
77
+ export class PollNode extends DecoratorNode<React.JSX.Element> {
78
78
  __question: string;
79
79
  __options: Options;
80
80
 
@@ -91,7 +91,7 @@ export class PollNode extends DecoratorNode<JSX.Element> {
91
91
  serializedNode.question,
92
92
  serializedNode.options,
93
93
  );
94
- serializedNode.options.forEach(node.addOption);
94
+ //serializedNode.options.forEach(node.addOption.bind(node));
95
95
  return node;
96
96
  }
97
97
 
@@ -185,7 +185,7 @@ export class PollNode extends DecoratorNode<JSX.Element> {
185
185
  return false;
186
186
  }
187
187
 
188
- decorate(): JSX.Element {
188
+ decorate(): React.JSX.Element {
189
189
  return (
190
190
  <Suspense fallback={null}>
191
191
  <PollComponent
@@ -735,7 +735,7 @@ function TableCellActionMenuContainer({
735
735
  setIsMenuOpen(!isMenuOpen);
736
736
  }}
737
737
  ref={menuRootRef}>
738
- <i className="chevron-down" />
738
+ <i className="angle-down" />
739
739
  </button>
740
740
 
741
741
  {isMenuOpen && (
@@ -6,16 +6,6 @@
6
6
  *
7
7
  *
8
8
  */
9
- .PlaygroundEditorTheme__ltr {
10
- text-align: left;
11
- }
12
- .PlaygroundEditorTheme__rtl {
13
- text-align: right;
14
- }
15
- .PlaygroundEditorTheme__paragraph {
16
- margin: 0;
17
- position: relative;
18
- }
19
9
  .PlaygroundEditorTheme__h1 {
20
10
  font-size: 24px;
21
11
  color: rgb(5, 5, 5);
@@ -416,18 +406,8 @@
416
406
  color: #ccc;
417
407
  }
418
408
  .PlaygroundEditorTheme__hr {
419
- padding: 2px 2px;
420
- border: none;
421
- margin: 1em 0;
422
409
  cursor: pointer;
423
410
  }
424
- .PlaygroundEditorTheme__hr:after {
425
- content: '';
426
- display: block;
427
- height: 2px;
428
- background-color: #ccc;
429
- line-height: 2px;
430
- }
431
411
  .PlaygroundEditorTheme__hr.selected {
432
412
  outline: 2px solid rgb(60, 132, 244);
433
413
  user-select: none;
@@ -84,12 +84,12 @@ const theme: EditorThemeClasses = {
84
84
  ],
85
85
  ul: 'liste',
86
86
  },
87
- ltr: 'PlaygroundEditorTheme__ltr',
87
+ ltr: '',
88
88
  mark: 'PlaygroundEditorTheme__mark',
89
89
  markOverlap: 'PlaygroundEditorTheme__markOverlap',
90
- paragraph: 'PlaygroundEditorTheme__paragraph',
90
+ paragraph: '',
91
91
  quote: '',
92
- rtl: 'PlaygroundEditorTheme__rtl',
92
+ rtl: 'txt-right',
93
93
  table: 'PlaygroundEditorTheme__table',
94
94
  tableCell: 'PlaygroundEditorTheme__tableCell',
95
95
  tableCellActionButton: 'PlaygroundEditorTheme__tableCellActionButton',
@@ -244,7 +244,7 @@ export default function DropDown({
244
244
  {buttonLabel && (
245
245
  <span className="text dropdown-button-text">{buttonLabel}</span>
246
246
  )}
247
- <i className="chevron-down" />
247
+ <i className="angle-down" />
248
248
  </button>
249
249
 
250
250
  {showDropDown &&