prosemirror-slash-menu-react 0.0.4 → 0.0.6

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.
@@ -0,0 +1,73 @@
1
+ .menu-display-root {
2
+ position: absolute;
3
+ display: flex;
4
+ flex-direction: column;
5
+ flex: 1;
6
+ max-height: 150px;
7
+ width: 200px;
8
+ z-index: 100;
9
+ overflow: scroll;
10
+ border-radius: 0.3rem;
11
+ background-color: #fafafa;
12
+ border: 2px solid #dddddd;
13
+ }
14
+
15
+ .menu-element-wrapper {
16
+ display: flex;
17
+ border-radius: 0.3rem;
18
+ padding: 0.2rem 0.5rem;
19
+ }
20
+
21
+ .menu-element-selected {
22
+ background-color: #f1f1f1;
23
+ }
24
+
25
+ .menu-element-icon {
26
+ width: 23px;
27
+ height: auto;
28
+ display: flex;
29
+ align-items: center;
30
+ }
31
+
32
+ .menu-element-label {
33
+ color: black;
34
+ display: flex;
35
+ align-items: center;
36
+ margin-left: 0.5rem;
37
+ }
38
+
39
+ .menu-placeholder {
40
+ color: #aaaaaa;
41
+ text-align: center;
42
+ padding-top: 1rem;
43
+ }
44
+
45
+ .menu-filter-wrapper {
46
+ display: flex;
47
+ background-color: transparent;
48
+ padding: 0.2rem 0.5rem;
49
+ position: absolute;
50
+ top: -1.5rem;
51
+ width: 200px;
52
+ }
53
+
54
+ .menu-filter-icon {
55
+ width: 23px;
56
+ height: auto;
57
+ display: flex;
58
+ align-items: center;
59
+ }
60
+
61
+ .menu-filter {
62
+ color: #aaaaaa;
63
+ font-style: italic
64
+ }
65
+
66
+ .menu-filter-placeholder {
67
+ color: #aaaaaa;
68
+ font-style: italic
69
+ }
70
+
71
+ .submenu-label {
72
+ margin-left: 0.5rem;
73
+ }
package/dist/index.es.js CHANGED
@@ -1,25 +1,14 @@
1
- import React, { useEffect, useMemo, useRef } from 'react';
2
- import { getElementById, SlashMenuKey, dispatchWithMeta, SlashMetaTypes } from 'prosemirror-slash-menu';
1
+ import React, { useEffect, useCallback, useMemo, useRef } from 'react';
2
+ import { dispatchWithMeta, SlashMenuKey, SlashMetaTypes, getElementById } from 'prosemirror-slash-menu';
3
3
  import { usePopper } from 'react-popper';
4
4
  import { setBlockType, toggleMark } from 'prosemirror-commands';
5
5
 
6
- const getElements = (state) => {
7
- const { subMenuId, filteredElements } = state;
8
- if (!subMenuId) {
9
- return filteredElements;
10
- }
11
- const subMenu = getElementById(subMenuId, state);
12
- if (subMenu && subMenu.type === "submenu") {
13
- return subMenu.elements;
14
- }
15
- };
16
-
17
- const ListItem = ({ menuState, id, Icon, idx, label }) => {
6
+ const ListItem = ({ menuState, el, view, Icon, idx, clickable, RightIcon }) => {
18
7
  useEffect(() => {
19
- const element = document.getElementById(id);
8
+ const element = document.getElementById(el.id);
20
9
  if (!element)
21
10
  return;
22
- if (id === menuState.selected) {
11
+ if (el.id === menuState.selected) {
23
12
  element.classList.add("menu-element-selected");
24
13
  return;
25
14
  }
@@ -27,10 +16,26 @@ const ListItem = ({ menuState, id, Icon, idx, label }) => {
27
16
  element.classList.remove("menu-element-selected");
28
17
  }
29
18
  }, [menuState.selected]);
30
- return (React.createElement("div", { className: "menu-element-wrapper", id: id, key: `${id}-${idx}` },
19
+ const handleOnClick = useCallback(() => {
20
+ if (el.type === "command") {
21
+ dispatchWithMeta(view, SlashMenuKey, {
22
+ type: SlashMetaTypes.execute,
23
+ });
24
+ el.command(view);
25
+ }
26
+ if (el.type === "submenu") {
27
+ dispatchWithMeta(view, SlashMenuKey, {
28
+ type: SlashMetaTypes.openSubMenu,
29
+ element: el,
30
+ });
31
+ }
32
+ }, [el]);
33
+ return (React.createElement("div", { className: clickable ? "menu-element-wrapper-clickable" : "menu-element-wrapper", id: el.id, key: `${el.id}-${idx}`, onClick: handleOnClick },
31
34
  Icon ? (React.createElement("div", { className: "menu-element-icon" },
32
35
  React.createElement(Icon, null))) : null,
33
- React.createElement("div", { className: "menu-element-label" }, label)));
36
+ React.createElement("div", { className: "menu-element-label" }, el.label),
37
+ RightIcon ? (React.createElement("div", { className: "menu-element-right-icon" },
38
+ React.createElement(RightIcon, null))) : null));
34
39
  };
35
40
 
36
41
  var Icons;
@@ -162,7 +167,25 @@ const defaultIcons = {
162
167
  ArrowRight,
163
168
  };
164
169
 
165
- const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
170
+ var Placement;
171
+ (function (Placement) {
172
+ Placement["auto"] = "auto";
173
+ Placement["autoStart"] = "auto-start";
174
+ Placement["autoEnd"] = "auto-end";
175
+ Placement["top"] = "top";
176
+ Placement["topStart"] = "top-start";
177
+ Placement["topEnd"] = "top-end";
178
+ Placement["bottom"] = "bottom";
179
+ Placement["bottomStart"] = "bottom-start";
180
+ Placement["bottomEnd"] = "bottom-end";
181
+ Placement["right"] = "right";
182
+ Placement["rightStart"] = "right-start";
183
+ Placement["rightEnd"] = "right-end";
184
+ Placement["left"] = "left";
185
+ Placement["leftStart"] = "left-start";
186
+ Placement["leftEnd"] = "left-end";
187
+ })(Placement || (Placement = {}));
188
+ const SlashMenuReact = ({ editorState, editorView, icons, rightIcons, subMenuIcon, filterFieldIcon, filterPlaceHolder, mainMenuLabel, popperReference, popperOptions, clickable, }) => {
166
189
  const menuState = useMemo(() => {
167
190
  if (!editorState)
168
191
  return;
@@ -171,7 +194,7 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
171
194
  const elements = useMemo(() => {
172
195
  if (!menuState)
173
196
  return;
174
- return getElements(menuState);
197
+ return menuState.filteredElements;
175
198
  }, [menuState]);
176
199
  const rootRef = useRef(null);
177
200
  useEffect(() => {
@@ -225,15 +248,28 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
225
248
  },
226
249
  };
227
250
  }, [editorState, window.scrollY]);
228
- const { styles, attributes } = usePopper(virtualReference, popperElement, {
251
+ const offsetModifier = useMemo(() => {
252
+ const filterElement = document.getElementById("menu-filter-wrapper");
253
+ filterElement === null || filterElement === void 0 ? void 0 : filterElement.getBoundingClientRect().top;
254
+ return {
255
+ name: "offset",
256
+ options: {
257
+ offset: [0, 36],
258
+ },
259
+ };
260
+ }, [popperReference]);
261
+ const { styles, attributes } = usePopper(popperReference || virtualReference, popperElement, {
262
+ placement: (popperOptions === null || popperOptions === void 0 ? void 0 : popperOptions.placement)
263
+ ? popperOptions.placement
264
+ : Placement.bottomStart,
229
265
  modifiers: [
230
266
  { name: "flip", enabled: true },
231
267
  {
232
268
  name: "preventOverflow",
233
- options: {
234
- mainAxis: false,
235
- },
236
269
  },
270
+ (popperOptions === null || popperOptions === void 0 ? void 0 : popperOptions.offsetModifier)
271
+ ? popperOptions.offsetModifier
272
+ : offsetModifier,
237
273
  ],
238
274
  });
239
275
  useEffect(() => {
@@ -280,18 +316,38 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
280
316
  return (_a = getElementById(menuState.subMenuId, menuState)) === null || _a === void 0 ? void 0 : _a.label;
281
317
  }
282
318
  }, [menuState]);
319
+ const closeSubMenu = useCallback(() => {
320
+ if (menuState === null || menuState === void 0 ? void 0 : menuState.subMenuId) {
321
+ dispatchWithMeta(editorView, SlashMenuKey, {
322
+ type: SlashMetaTypes.closeSubMenu,
323
+ element: getElementById(menuState.subMenuId, menuState),
324
+ });
325
+ }
326
+ }, [menuState]);
327
+ useEffect(() => {
328
+ editorView.focus();
329
+ }, [menuState === null || menuState === void 0 ? void 0 : menuState.open]);
330
+ useEffect(() => {
331
+ console.log("focusSubId");
332
+ editorView.focus();
333
+ }, [menuState === null || menuState === void 0 ? void 0 : menuState.subMenuId]);
283
334
  return (React.createElement(React.Fragment, null, (menuState === null || menuState === void 0 ? void 0 : menuState.open) ? (React.createElement("div", Object.assign({
284
335
  // @ts-ignore
285
336
  ref: setPopperElement, style: Object.assign({}, styles.popper) }, attributes.popper),
286
337
  menuState.filter ? (React.createElement("div", { className: "menu-filter-wrapper" },
287
- React.createElement("div", { id: "menu-filter", className: "menu-filter" }, menuState.filter))) : null,
338
+ filterFieldIcon ? (React.createElement("div", { className: "menu-filter-icon" }, filterFieldIcon)) : null,
339
+ React.createElement("div", { id: "menu-filter", className: "menu-filter" }, menuState.filter))) : (React.createElement("div", { className: "menu-filter-wrapper" },
340
+ filterFieldIcon ? (React.createElement("div", { className: "menu-filter-icon" }, filterFieldIcon)) : null,
341
+ React.createElement("div", { className: "menu-filter-placeholder" }, filterPlaceHolder))),
288
342
  React.createElement("div", { id: "slashDisplay", ref: rootRef, className: "menu-display-root" },
289
- menuState.subMenuId ? (React.createElement("div", { className: "menu-element-wrapper" },
290
- React.createElement("div", { className: "menu-element-icon" }, subMenuIcon || defaultIcons.ArrowLeft()),
291
- React.createElement("div", { className: "submenu-label" }, subMenuLabel))) : null, elements === null || elements === void 0 ? void 0 :
292
- elements.map((el, idx) => (React.createElement(ListItem, { key: el.id, menuState: menuState, id: el.id, Icon: icons === null || icons === void 0 ? void 0 : icons[el.id], idx: idx, label: el.label }))),
343
+ menuState.subMenuId ? (React.createElement("div", { className: "menu-element-wrapper", onClick: clickable ? closeSubMenu : undefined, style: { cursor: clickable ? "pointer" : undefined } },
344
+ React.createElement("div", { className: "menu-element-icon-left" }, subMenuIcon || defaultIcons.ArrowLeft()),
345
+ React.createElement("div", { className: "submenu-label" }, subMenuLabel))) : null,
346
+ !menuState.subMenuId && mainMenuLabel ? (React.createElement("div", { className: "menu-element-wrapper" },
347
+ React.createElement("div", { className: "submenu-label" }, mainMenuLabel))) : null, elements === null || elements === void 0 ? void 0 :
348
+ elements.map((el, idx) => (React.createElement(ListItem, { key: el.id, menuState: menuState, Icon: icons === null || icons === void 0 ? void 0 : icons[el.id], RightIcon: rightIcons === null || rightIcons === void 0 ? void 0 : rightIcons[el.id], idx: idx, clickable: clickable, el: el, view: editorView }))),
293
349
  (elements === null || elements === void 0 ? void 0 : elements.length) === 0 ? (React.createElement("div", { className: "menu-placeholder" }, "No matching items")) : null))) : null));
294
350
  };
295
351
 
296
- export { Icons, SlashMenuReact, defaultElements, defaultIcons };
352
+ export { Icons, Placement, SlashMenuReact, defaultElements, defaultIcons };
297
353
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.js CHANGED
@@ -11,23 +11,12 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
11
11
 
12
12
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
13
 
14
- const getElements = (state) => {
15
- const { subMenuId, filteredElements } = state;
16
- if (!subMenuId) {
17
- return filteredElements;
18
- }
19
- const subMenu = prosemirrorSlashMenu.getElementById(subMenuId, state);
20
- if (subMenu && subMenu.type === "submenu") {
21
- return subMenu.elements;
22
- }
23
- };
24
-
25
- const ListItem = ({ menuState, id, Icon, idx, label }) => {
14
+ const ListItem = ({ menuState, el, view, Icon, idx, clickable, RightIcon }) => {
26
15
  React.useEffect(() => {
27
- const element = document.getElementById(id);
16
+ const element = document.getElementById(el.id);
28
17
  if (!element)
29
18
  return;
30
- if (id === menuState.selected) {
19
+ if (el.id === menuState.selected) {
31
20
  element.classList.add("menu-element-selected");
32
21
  return;
33
22
  }
@@ -35,10 +24,26 @@ const ListItem = ({ menuState, id, Icon, idx, label }) => {
35
24
  element.classList.remove("menu-element-selected");
36
25
  }
37
26
  }, [menuState.selected]);
38
- return (React__default["default"].createElement("div", { className: "menu-element-wrapper", id: id, key: `${id}-${idx}` },
27
+ const handleOnClick = React.useCallback(() => {
28
+ if (el.type === "command") {
29
+ prosemirrorSlashMenu.dispatchWithMeta(view, prosemirrorSlashMenu.SlashMenuKey, {
30
+ type: prosemirrorSlashMenu.SlashMetaTypes.execute,
31
+ });
32
+ el.command(view);
33
+ }
34
+ if (el.type === "submenu") {
35
+ prosemirrorSlashMenu.dispatchWithMeta(view, prosemirrorSlashMenu.SlashMenuKey, {
36
+ type: prosemirrorSlashMenu.SlashMetaTypes.openSubMenu,
37
+ element: el,
38
+ });
39
+ }
40
+ }, [el]);
41
+ return (React__default["default"].createElement("div", { className: clickable ? "menu-element-wrapper-clickable" : "menu-element-wrapper", id: el.id, key: `${el.id}-${idx}`, onClick: handleOnClick },
39
42
  Icon ? (React__default["default"].createElement("div", { className: "menu-element-icon" },
40
43
  React__default["default"].createElement(Icon, null))) : null,
41
- React__default["default"].createElement("div", { className: "menu-element-label" }, label)));
44
+ React__default["default"].createElement("div", { className: "menu-element-label" }, el.label),
45
+ RightIcon ? (React__default["default"].createElement("div", { className: "menu-element-right-icon" },
46
+ React__default["default"].createElement(RightIcon, null))) : null));
42
47
  };
43
48
 
44
49
  exports.Icons = void 0;
@@ -170,7 +175,25 @@ const defaultIcons = {
170
175
  ArrowRight,
171
176
  };
172
177
 
173
- const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
178
+ exports.Placement = void 0;
179
+ (function (Placement) {
180
+ Placement["auto"] = "auto";
181
+ Placement["autoStart"] = "auto-start";
182
+ Placement["autoEnd"] = "auto-end";
183
+ Placement["top"] = "top";
184
+ Placement["topStart"] = "top-start";
185
+ Placement["topEnd"] = "top-end";
186
+ Placement["bottom"] = "bottom";
187
+ Placement["bottomStart"] = "bottom-start";
188
+ Placement["bottomEnd"] = "bottom-end";
189
+ Placement["right"] = "right";
190
+ Placement["rightStart"] = "right-start";
191
+ Placement["rightEnd"] = "right-end";
192
+ Placement["left"] = "left";
193
+ Placement["leftStart"] = "left-start";
194
+ Placement["leftEnd"] = "left-end";
195
+ })(exports.Placement || (exports.Placement = {}));
196
+ const SlashMenuReact = ({ editorState, editorView, icons, rightIcons, subMenuIcon, filterFieldIcon, filterPlaceHolder, mainMenuLabel, popperReference, popperOptions, clickable, }) => {
174
197
  const menuState = React.useMemo(() => {
175
198
  if (!editorState)
176
199
  return;
@@ -179,7 +202,7 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
179
202
  const elements = React.useMemo(() => {
180
203
  if (!menuState)
181
204
  return;
182
- return getElements(menuState);
205
+ return menuState.filteredElements;
183
206
  }, [menuState]);
184
207
  const rootRef = React.useRef(null);
185
208
  React.useEffect(() => {
@@ -233,15 +256,28 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
233
256
  },
234
257
  };
235
258
  }, [editorState, window.scrollY]);
236
- const { styles, attributes } = reactPopper.usePopper(virtualReference, popperElement, {
259
+ const offsetModifier = React.useMemo(() => {
260
+ const filterElement = document.getElementById("menu-filter-wrapper");
261
+ filterElement === null || filterElement === void 0 ? void 0 : filterElement.getBoundingClientRect().top;
262
+ return {
263
+ name: "offset",
264
+ options: {
265
+ offset: [0, 36],
266
+ },
267
+ };
268
+ }, [popperReference]);
269
+ const { styles, attributes } = reactPopper.usePopper(popperReference || virtualReference, popperElement, {
270
+ placement: (popperOptions === null || popperOptions === void 0 ? void 0 : popperOptions.placement)
271
+ ? popperOptions.placement
272
+ : exports.Placement.bottomStart,
237
273
  modifiers: [
238
274
  { name: "flip", enabled: true },
239
275
  {
240
276
  name: "preventOverflow",
241
- options: {
242
- mainAxis: false,
243
- },
244
277
  },
278
+ (popperOptions === null || popperOptions === void 0 ? void 0 : popperOptions.offsetModifier)
279
+ ? popperOptions.offsetModifier
280
+ : offsetModifier,
245
281
  ],
246
282
  });
247
283
  React.useEffect(() => {
@@ -288,16 +324,36 @@ const SlashMenuReact = ({ editorState, editorView, icons, subMenuIcon, }) => {
288
324
  return (_a = prosemirrorSlashMenu.getElementById(menuState.subMenuId, menuState)) === null || _a === void 0 ? void 0 : _a.label;
289
325
  }
290
326
  }, [menuState]);
327
+ const closeSubMenu = React.useCallback(() => {
328
+ if (menuState === null || menuState === void 0 ? void 0 : menuState.subMenuId) {
329
+ prosemirrorSlashMenu.dispatchWithMeta(editorView, prosemirrorSlashMenu.SlashMenuKey, {
330
+ type: prosemirrorSlashMenu.SlashMetaTypes.closeSubMenu,
331
+ element: prosemirrorSlashMenu.getElementById(menuState.subMenuId, menuState),
332
+ });
333
+ }
334
+ }, [menuState]);
335
+ React.useEffect(() => {
336
+ editorView.focus();
337
+ }, [menuState === null || menuState === void 0 ? void 0 : menuState.open]);
338
+ React.useEffect(() => {
339
+ console.log("focusSubId");
340
+ editorView.focus();
341
+ }, [menuState === null || menuState === void 0 ? void 0 : menuState.subMenuId]);
291
342
  return (React__default["default"].createElement(React__default["default"].Fragment, null, (menuState === null || menuState === void 0 ? void 0 : menuState.open) ? (React__default["default"].createElement("div", Object.assign({
292
343
  // @ts-ignore
293
344
  ref: setPopperElement, style: Object.assign({}, styles.popper) }, attributes.popper),
294
345
  menuState.filter ? (React__default["default"].createElement("div", { className: "menu-filter-wrapper" },
295
- React__default["default"].createElement("div", { id: "menu-filter", className: "menu-filter" }, menuState.filter))) : null,
346
+ filterFieldIcon ? (React__default["default"].createElement("div", { className: "menu-filter-icon" }, filterFieldIcon)) : null,
347
+ React__default["default"].createElement("div", { id: "menu-filter", className: "menu-filter" }, menuState.filter))) : (React__default["default"].createElement("div", { className: "menu-filter-wrapper" },
348
+ filterFieldIcon ? (React__default["default"].createElement("div", { className: "menu-filter-icon" }, filterFieldIcon)) : null,
349
+ React__default["default"].createElement("div", { className: "menu-filter-placeholder" }, filterPlaceHolder))),
296
350
  React__default["default"].createElement("div", { id: "slashDisplay", ref: rootRef, className: "menu-display-root" },
297
- menuState.subMenuId ? (React__default["default"].createElement("div", { className: "menu-element-wrapper" },
298
- React__default["default"].createElement("div", { className: "menu-element-icon" }, subMenuIcon || defaultIcons.ArrowLeft()),
299
- React__default["default"].createElement("div", { className: "submenu-label" }, subMenuLabel))) : null, elements === null || elements === void 0 ? void 0 :
300
- elements.map((el, idx) => (React__default["default"].createElement(ListItem, { key: el.id, menuState: menuState, id: el.id, Icon: icons === null || icons === void 0 ? void 0 : icons[el.id], idx: idx, label: el.label }))),
351
+ menuState.subMenuId ? (React__default["default"].createElement("div", { className: "menu-element-wrapper", onClick: clickable ? closeSubMenu : undefined, style: { cursor: clickable ? "pointer" : undefined } },
352
+ React__default["default"].createElement("div", { className: "menu-element-icon-left" }, subMenuIcon || defaultIcons.ArrowLeft()),
353
+ React__default["default"].createElement("div", { className: "submenu-label" }, subMenuLabel))) : null,
354
+ !menuState.subMenuId && mainMenuLabel ? (React__default["default"].createElement("div", { className: "menu-element-wrapper" },
355
+ React__default["default"].createElement("div", { className: "submenu-label" }, mainMenuLabel))) : null, elements === null || elements === void 0 ? void 0 :
356
+ elements.map((el, idx) => (React__default["default"].createElement(ListItem, { key: el.id, menuState: menuState, Icon: icons === null || icons === void 0 ? void 0 : icons[el.id], RightIcon: rightIcons === null || rightIcons === void 0 ? void 0 : rightIcons[el.id], idx: idx, clickable: clickable, el: el, view: editorView }))),
301
357
  (elements === null || elements === void 0 ? void 0 : elements.length) === 0 ? (React__default["default"].createElement("div", { className: "menu-placeholder" }, "No matching items")) : null))) : null));
302
358
  };
303
359
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,10 +1,13 @@
1
1
  import { FC } from "react";
2
- import { SlashMenuState } from "prosemirror-slash-menu";
2
+ import { MenuElement, SlashMenuState } from "prosemirror-slash-menu";
3
3
  import "./styles/menu-style.css";
4
+ import { EditorView } from "prosemirror-view";
4
5
  export declare const ListItem: FC<{
5
6
  menuState: SlashMenuState;
6
- id: string;
7
- Icon?: FC;
7
+ el: MenuElement;
8
+ view: EditorView;
8
9
  idx: number;
9
- label: string;
10
+ Icon?: FC;
11
+ RightIcon?: FC;
12
+ clickable?: boolean;
10
13
  }>;
@@ -1,4 +1,5 @@
1
1
  import { CommandItem, SubMenu } from "prosemirror-slash-menu";
2
+ import React from "react";
2
3
  export declare enum Icons {
3
4
  "HeaderMenu" = "HeaderMenu",
4
5
  "Level1" = "Level1",
@@ -10,7 +11,6 @@ export declare enum Icons {
10
11
  "Code" = "Code"
11
12
  }
12
13
  export declare const defaultElements: (CommandItem | SubMenu)[];
13
- import React from "react";
14
14
  export declare const defaultIcons: {
15
15
  H1Icon: () => React.JSX.Element;
16
16
  H2Icon: () => React.JSX.Element;
@@ -2,12 +2,47 @@ import { FC, ReactNode } from "react";
2
2
  import { EditorState } from "prosemirror-state";
3
3
  import { EditorView } from "prosemirror-view";
4
4
  import "./styles/menu-style.css";
5
+ export declare enum Placement {
6
+ auto = "auto",
7
+ autoStart = "auto-start",
8
+ autoEnd = "auto-end",
9
+ top = "top",
10
+ topStart = "top-start",
11
+ topEnd = "top-end",
12
+ bottom = "bottom",
13
+ bottomStart = "bottom-start",
14
+ bottomEnd = "bottom-end",
15
+ right = "right",
16
+ rightStart = "right-start",
17
+ rightEnd = "right-end",
18
+ left = "left",
19
+ leftStart = "left-start",
20
+ leftEnd = "left-end"
21
+ }
22
+ export interface PopperOptions {
23
+ placement: Placement;
24
+ offsetModifier: {
25
+ name: string;
26
+ options: {
27
+ offset: number[];
28
+ };
29
+ };
30
+ }
5
31
  export interface SlashMenuProps {
6
32
  editorState: EditorState;
7
33
  editorView: EditorView;
8
34
  icons?: {
9
35
  [key: string]: FC;
10
36
  };
37
+ rightIcons?: {
38
+ [key: string]: FC;
39
+ };
11
40
  subMenuIcon?: ReactNode;
41
+ filterFieldIcon?: ReactNode;
42
+ filterPlaceHolder?: string;
43
+ mainMenuLabel?: string;
44
+ popperReference?: HTMLElement;
45
+ popperOptions?: PopperOptions;
46
+ clickable?: boolean;
12
47
  }
13
48
  export declare const SlashMenuReact: FC<SlashMenuProps>;
@@ -1,60 +1,89 @@
1
1
  .menu-display-root {
2
- position: absolute;
3
- display: flex;
4
- flex-direction: column;
5
- height: 150px;
6
- width: 200px;
7
- z-index: 100;
8
- overflow: scroll;
9
- border-radius: 0.3rem;
10
- background-color: #fafafa;
11
- border: 2px solid #dddddd;
2
+ position: absolute;
3
+ display: flex;
4
+ flex-direction: column;
5
+ flex: 1;
6
+ max-height: 150px;
7
+ width: 200px;
8
+ z-index: 100;
9
+ overflow: scroll;
10
+ border-radius: 0.3rem;
11
+ background-color: #fafafa;
12
+ border: 2px solid #dddddd;
12
13
  }
13
14
 
14
15
  .menu-element-wrapper {
15
- display: flex;
16
- border-radius: 0.3rem;
17
- padding: 0.2rem 0.5rem;
16
+ display: flex;
17
+ border-radius: 0.3rem;
18
+ padding: 0.2rem 0.5rem;
19
+ }
20
+
21
+ .menu-element-wrapper-clickable {
22
+ display: flex;
23
+ border-radius: 0.3rem;
24
+ padding: 0.2rem 0.5rem;
25
+ cursor: pointer;
18
26
  }
19
27
 
20
28
  .menu-element-selected {
21
- background-color: #f1f1f1;
29
+ background-color: #f1f1f1;
22
30
  }
23
31
 
24
32
  .menu-element-icon {
25
- width: 23px;
26
- height: auto;
27
- display: flex;
28
- align-items: center;
33
+ width: 23px;
34
+ height: auto;
35
+ display: flex;
36
+ align-items: center;
37
+ }
38
+
39
+ .menu-element-right-icon {
40
+ margin-left: auto;
41
+ width: 23px;
42
+ height: auto;
43
+ display: flex;
44
+ align-items: center;
45
+ margin-right: 0.5rem;
29
46
  }
30
47
 
31
48
  .menu-element-label {
32
- color: black;
33
- display: flex;
34
- align-items: center;
35
- margin-left: 0.5rem;
49
+ color: black;
50
+ display: flex;
51
+ align-items: center;
52
+ margin-left: 0.5rem;
36
53
  }
37
54
 
38
55
  .menu-placeholder {
39
- color: #aaaaaa;
40
- text-align: center;
41
- padding-top: 1rem;
56
+ color: #aaaaaa;
57
+ text-align: center;
58
+ padding: 0 0.5rem;
42
59
  }
43
60
 
44
61
  .menu-filter-wrapper {
45
- display: flex;
46
- background-color: transparent;
47
- padding: 0.2rem 0.5rem;
48
- position: absolute;
49
- top: -1.5rem;
62
+ display: flex;
63
+ background-color: transparent;
64
+ padding: 0.2rem 0.5rem;
65
+ position: absolute;
66
+ top: -1.5rem;
67
+ width: 200px;
68
+ }
69
+
70
+ .menu-filter-icon {
71
+ width: 23px;
72
+ height: auto;
73
+ display: flex;
74
+ align-items: center;
50
75
  }
51
76
 
52
77
  .menu-filter {
53
- color: #aaaaaa;
54
- font-style: italic;
78
+ color: #aaaaaa;
79
+ font-style: italic
55
80
  }
56
81
 
82
+ .menu-filter-placeholder {
83
+ color: #aaaaaa;
84
+ font-style: italic
85
+ }
57
86
 
58
- .submenu-label{
59
- margin-left: 0.5rem;
87
+ .submenu-label {
88
+ margin-left: 0.5rem;
60
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prosemirror-slash-menu-react",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Implementation of prosemirror-slash-menu in react",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -20,7 +20,7 @@
20
20
  "prettier": "^2.8.8",
21
21
  "prosemirror-commands": "^1.5.2",
22
22
  "prosemirror-schema-basic": "^1.2.2",
23
- "prosemirror-slash-menu": "^0.1.2",
23
+ "prosemirror-slash-menu": "^0.1.4",
24
24
  "prosemirror-view": "^1.31.4",
25
25
  "react": "^18.2.0",
26
26
  "react-dom": "^18.2.0",
@@ -1,9 +0,0 @@
1
- import { FC } from "react";
2
- import { SlashMenuState } from "prosemirror-slash-menu";
3
- export declare const ListItem: FC<{
4
- menuState: SlashMenuState;
5
- id: string;
6
- Icon?: FC;
7
- idx: number;
8
- label: string;
9
- }>;