@plasmicpkgs/tiptap 0.0.1

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.
Files changed (103) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +1 -0
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/components/MentionList.d.ts +12 -0
  5. package/dist/contexts.d.ts +30 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +1400 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/registerBold.d.ts +9 -0
  10. package/dist/registerCode.d.ts +9 -0
  11. package/dist/registerItalic.d.ts +9 -0
  12. package/dist/registerLink.d.ts +9 -0
  13. package/dist/registerMention.d.ts +28 -0
  14. package/dist/registerStrike.d.ts +9 -0
  15. package/dist/registerTiptap.d.ts +18 -0
  16. package/dist/registerUnderline.d.ts +9 -0
  17. package/dist/tiptap.esm.js +1382 -0
  18. package/dist/tiptap.esm.js.map +1 -0
  19. package/dist/toolbar/registerToolbarBold.d.ts +13 -0
  20. package/dist/toolbar/registerToolbarCode.d.ts +13 -0
  21. package/dist/toolbar/registerToolbarItalic.d.ts +13 -0
  22. package/dist/toolbar/registerToolbarLink.d.ts +13 -0
  23. package/dist/toolbar/registerToolbarMention.d.ts +13 -0
  24. package/dist/toolbar/registerToolbarStrike.d.ts +13 -0
  25. package/dist/toolbar/registerToolbarUnderline.d.ts +13 -0
  26. package/dist/useIsClient.d.ts +3 -0
  27. package/dist/utils.d.ts +24 -0
  28. package/package.json +103 -0
  29. package/skinny/contexts.d.ts +30 -0
  30. package/skinny/registerBold.cjs.js +48 -0
  31. package/skinny/registerBold.cjs.js.map +1 -0
  32. package/skinny/registerBold.d.ts +9 -0
  33. package/skinny/registerBold.esm.js +41 -0
  34. package/skinny/registerBold.esm.js.map +1 -0
  35. package/skinny/registerCode.cjs.js +48 -0
  36. package/skinny/registerCode.cjs.js.map +1 -0
  37. package/skinny/registerCode.d.ts +9 -0
  38. package/skinny/registerCode.esm.js +41 -0
  39. package/skinny/registerCode.esm.js.map +1 -0
  40. package/skinny/registerItalic.cjs.js +48 -0
  41. package/skinny/registerItalic.cjs.js.map +1 -0
  42. package/skinny/registerItalic.d.ts +9 -0
  43. package/skinny/registerItalic.esm.js +41 -0
  44. package/skinny/registerItalic.esm.js.map +1 -0
  45. package/skinny/registerLink.cjs.js +48 -0
  46. package/skinny/registerLink.cjs.js.map +1 -0
  47. package/skinny/registerLink.d.ts +9 -0
  48. package/skinny/registerLink.esm.js +41 -0
  49. package/skinny/registerLink.esm.js.map +1 -0
  50. package/skinny/registerMention.cjs.js +420 -0
  51. package/skinny/registerMention.cjs.js.map +1 -0
  52. package/skinny/registerMention.d.ts +28 -0
  53. package/skinny/registerMention.esm.js +411 -0
  54. package/skinny/registerMention.esm.js.map +1 -0
  55. package/skinny/registerStrike.cjs.js +48 -0
  56. package/skinny/registerStrike.cjs.js.map +1 -0
  57. package/skinny/registerStrike.d.ts +9 -0
  58. package/skinny/registerStrike.esm.js +41 -0
  59. package/skinny/registerStrike.esm.js.map +1 -0
  60. package/skinny/registerTiptap-6a2d0bb4.esm.js +375 -0
  61. package/skinny/registerTiptap-6a2d0bb4.esm.js.map +1 -0
  62. package/skinny/registerTiptap-fd9bf882.cjs.js +391 -0
  63. package/skinny/registerTiptap-fd9bf882.cjs.js.map +1 -0
  64. package/skinny/registerTiptap.cjs.js +20 -0
  65. package/skinny/registerTiptap.cjs.js.map +1 -0
  66. package/skinny/registerTiptap.d.ts +18 -0
  67. package/skinny/registerTiptap.esm.js +10 -0
  68. package/skinny/registerTiptap.esm.js.map +1 -0
  69. package/skinny/registerToolbarBold.cjs.js +78 -0
  70. package/skinny/registerToolbarBold.cjs.js.map +1 -0
  71. package/skinny/registerToolbarBold.esm.js +71 -0
  72. package/skinny/registerToolbarBold.esm.js.map +1 -0
  73. package/skinny/registerToolbarCode.cjs.js +78 -0
  74. package/skinny/registerToolbarCode.cjs.js.map +1 -0
  75. package/skinny/registerToolbarCode.esm.js +71 -0
  76. package/skinny/registerToolbarCode.esm.js.map +1 -0
  77. package/skinny/registerToolbarItalic.cjs.js +81 -0
  78. package/skinny/registerToolbarItalic.cjs.js.map +1 -0
  79. package/skinny/registerToolbarItalic.esm.js +74 -0
  80. package/skinny/registerToolbarItalic.esm.js.map +1 -0
  81. package/skinny/registerToolbarLink.cjs.js +78 -0
  82. package/skinny/registerToolbarLink.cjs.js.map +1 -0
  83. package/skinny/registerToolbarLink.esm.js +71 -0
  84. package/skinny/registerToolbarLink.esm.js.map +1 -0
  85. package/skinny/registerToolbarMention.cjs.js +78 -0
  86. package/skinny/registerToolbarMention.cjs.js.map +1 -0
  87. package/skinny/registerToolbarMention.esm.js +71 -0
  88. package/skinny/registerToolbarMention.esm.js.map +1 -0
  89. package/skinny/registerToolbarStrike.cjs.js +78 -0
  90. package/skinny/registerToolbarStrike.cjs.js.map +1 -0
  91. package/skinny/registerToolbarStrike.esm.js +71 -0
  92. package/skinny/registerToolbarStrike.esm.js.map +1 -0
  93. package/skinny/registerToolbarUnderline.cjs.js +78 -0
  94. package/skinny/registerToolbarUnderline.cjs.js.map +1 -0
  95. package/skinny/registerToolbarUnderline.esm.js +71 -0
  96. package/skinny/registerToolbarUnderline.esm.js.map +1 -0
  97. package/skinny/registerUnderline.cjs.js +48 -0
  98. package/skinny/registerUnderline.cjs.js.map +1 -0
  99. package/skinny/registerUnderline.d.ts +9 -0
  100. package/skinny/registerUnderline.esm.js +41 -0
  101. package/skinny/registerUnderline.esm.js.map +1 -0
  102. package/skinny/useIsClient.d.ts +3 -0
  103. package/skinny/utils.d.ts +24 -0
@@ -0,0 +1,1382 @@
1
+ import TiptapBold from '@tiptap/extension-bold';
2
+ import React, { useState, useMemo, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
3
+ import Document from '@tiptap/extension-document';
4
+ import Paragraph from '@tiptap/extension-paragraph';
5
+ import Text from '@tiptap/extension-text';
6
+ import { EditorProvider, ReactRenderer, useCurrentEditor } from '@tiptap/react';
7
+ import { Switch } from 'antd';
8
+ import registerComponent from '@plasmicapp/host/registerComponent';
9
+ import '@plasmicapp/host/registerGlobalContext';
10
+ import TiptapCode from '@tiptap/extension-code';
11
+ import TiptapItalic from '@tiptap/extension-italic';
12
+ import TiptapLink from '@tiptap/extension-link';
13
+ import { DataProvider, repeatedElement, usePlasmicCanvasContext } from '@plasmicapp/host';
14
+ import TiptapMention from '@tiptap/extension-mention';
15
+ import tippy from 'tippy.js';
16
+ import TiptapStrike from '@tiptap/extension-strike';
17
+ import TiptapUnderline from '@tiptap/extension-underline';
18
+
19
+ const RESET_TIMEOUT_MS = 500;
20
+ const allExtensions = [
21
+ "bold",
22
+ "italic",
23
+ "underline",
24
+ "strike",
25
+ "code",
26
+ "link",
27
+ "mention"
28
+ ];
29
+ const TiptapContext = React.createContext(void 0);
30
+ const useTiptapContext = () => {
31
+ const context = React.useContext(TiptapContext);
32
+ if (!context) {
33
+ throw new Error(
34
+ "useTiptapContext must be used within a TiptapContextProvider"
35
+ );
36
+ }
37
+ return context;
38
+ };
39
+ const TiptapContextProvider = ({ children }) => {
40
+ const [bold, setBold] = useState(void 0);
41
+ const [code, setCode] = useState(void 0);
42
+ const [italic, setItalic] = useState(
43
+ void 0
44
+ );
45
+ const [link, setLink] = useState(void 0);
46
+ const [mention, setMention] = useState(
47
+ void 0
48
+ );
49
+ const [strike, setStrike] = useState(
50
+ void 0
51
+ );
52
+ const [underline, setUnderline] = useState(void 0);
53
+ return /* @__PURE__ */ React.createElement(
54
+ TiptapContext.Provider,
55
+ {
56
+ value: {
57
+ bold,
58
+ setBold,
59
+ code,
60
+ setCode,
61
+ italic,
62
+ setItalic,
63
+ link,
64
+ setLink,
65
+ mention,
66
+ /**
67
+ * In situations where I want to remove an extension and add it again with new options (e.g. within a useEffect - see registerMention)
68
+ * the options are not updated.
69
+ * So after removing the extension, I want to wait a few seconds before I add it again,
70
+ * so the Tiptap editor acknowledges the removal before it adds the extension back with new updated options.
71
+ * @param mentionOptions
72
+ * @returns
73
+ */
74
+ setMention: (mentionOptions) => {
75
+ if (!mentionOptions) {
76
+ setMention(mentionOptions);
77
+ return;
78
+ }
79
+ setTimeout(() => {
80
+ setMention(mentionOptions);
81
+ }, RESET_TIMEOUT_MS);
82
+ },
83
+ strike,
84
+ setStrike,
85
+ underline,
86
+ setUnderline
87
+ }
88
+ },
89
+ children
90
+ );
91
+ };
92
+
93
+ function useIsClient() {
94
+ const [loaded, setLoaded] = React.useState(false);
95
+ useIsomorphicLayoutEffect(() => {
96
+ setLoaded(true);
97
+ });
98
+ return loaded;
99
+ }
100
+ const isBrowser = typeof window !== "undefined";
101
+ const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
102
+
103
+ function registerComponentHelper(loader, component, meta) {
104
+ if (loader) {
105
+ loader.registerComponent(component, meta);
106
+ } else {
107
+ registerComponent(component, meta);
108
+ }
109
+ }
110
+ function traverseReactEltTree(children, callback) {
111
+ const rec = (elts) => {
112
+ (Array.isArray(elts) ? elts : [elts]).forEach((elt) => {
113
+ var _a;
114
+ if (elt) {
115
+ callback(elt);
116
+ if (elt.children) {
117
+ rec(elt.children);
118
+ }
119
+ if (((_a = elt.props) == null ? void 0 : _a.children) && elt.props.children !== elt.children) {
120
+ rec(elt.props.children);
121
+ }
122
+ }
123
+ });
124
+ };
125
+ rec(children);
126
+ }
127
+
128
+ var __defProp$1 = Object.defineProperty;
129
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
130
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
131
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
132
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
133
+ var __spreadValues$1 = (a, b) => {
134
+ for (var prop in b || (b = {}))
135
+ if (__hasOwnProp$1.call(b, prop))
136
+ __defNormalProp$1(a, prop, b[prop]);
137
+ if (__getOwnPropSymbols$1)
138
+ for (var prop of __getOwnPropSymbols$1(b)) {
139
+ if (__propIsEnum$1.call(b, prop))
140
+ __defNormalProp$1(a, prop, b[prop]);
141
+ }
142
+ return a;
143
+ };
144
+ var __objRest = (source, exclude) => {
145
+ var target = {};
146
+ for (var prop in source)
147
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
148
+ target[prop] = source[prop];
149
+ if (source != null && __getOwnPropSymbols$1)
150
+ for (var prop of __getOwnPropSymbols$1(source)) {
151
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
152
+ target[prop] = source[prop];
153
+ }
154
+ return target;
155
+ };
156
+ const TIPTAP_COMPONENT_NAME = "hostless-tiptap";
157
+ function Tiptap(props) {
158
+ const isClient = useIsClient();
159
+ const [active, setActive] = useState(false);
160
+ const [refreshKey, setRefreshKey] = useState(0);
161
+ const activeRef = useRef();
162
+ activeRef.current = active;
163
+ const {
164
+ extensions,
165
+ contentHtml,
166
+ defaultContentHtml,
167
+ className,
168
+ onChange,
169
+ toolbar
170
+ } = props;
171
+ const tiptapContext = __objRest(useTiptapContext(), []);
172
+ const usedExtensions = allExtensions.reduce(
173
+ (acc, ext) => {
174
+ if (tiptapContext[ext] !== void 0) {
175
+ acc[ext] = tiptapContext[ext];
176
+ }
177
+ return acc;
178
+ },
179
+ {}
180
+ );
181
+ const extensionsProp = [
182
+ Document,
183
+ Paragraph,
184
+ Text,
185
+ ...Object.values(usedExtensions)
186
+ ];
187
+ useEffect(() => {
188
+ if (activeRef.current)
189
+ return;
190
+ setRefreshKey(Math.random() * 1e6);
191
+ }, [contentHtml]);
192
+ if (!isClient) {
193
+ return null;
194
+ }
195
+ const css = `
196
+ .tiptap {
197
+ padding: 0;
198
+ outline: none;
199
+ }
200
+ `;
201
+ const toolbarProp = toolbar ? /* @__PURE__ */ React.createElement("div", { style: { display: "flex", alignItems: "center" } }, toolbar) : null;
202
+ return /* @__PURE__ */ React.createElement("div", { className, style: { position: "relative" } }, /* @__PURE__ */ React.createElement(
203
+ EditorProvider,
204
+ {
205
+ key: `${extensionsProp.length}${refreshKey}`,
206
+ extensions: extensionsProp,
207
+ content: contentHtml || defaultContentHtml,
208
+ onCreate: ({ editor }) => {
209
+ onChange(editor.getJSON());
210
+ },
211
+ onUpdate: ({ editor }) => {
212
+ onChange(editor.getJSON());
213
+ },
214
+ onFocus: () => setActive(true),
215
+ onBlur: () => setActive(false),
216
+ slotBefore: toolbarProp,
217
+ children: void 0,
218
+ editorProps: {
219
+ attributes: {
220
+ className
221
+ }
222
+ }
223
+ }
224
+ ), extensions, /* @__PURE__ */ React.createElement("style", { dangerouslySetInnerHTML: { __html: css } }));
225
+ }
226
+ function TiptapWrapper(props) {
227
+ return /* @__PURE__ */ React.createElement(TiptapContextProvider, null, /* @__PURE__ */ React.createElement(Tiptap, __spreadValues$1({}, props)));
228
+ }
229
+ function AddExtension({
230
+ studioOps,
231
+ componentProps
232
+ }) {
233
+ const usedExtensions = useMemo(() => {
234
+ const list = [];
235
+ traverseReactEltTree(componentProps == null ? void 0 : componentProps.extensions, (elt) => {
236
+ var _a, _b, _c;
237
+ const ext = (_c = (_b = (_a = elt == null ? void 0 : elt.type) == null ? void 0 : _a.displayName) == null ? void 0 : _b.toLowerCase) == null ? void 0 : _c.call(_b);
238
+ if (ext) {
239
+ list.push(ext);
240
+ }
241
+ });
242
+ return list;
243
+ }, [componentProps == null ? void 0 : componentProps.extensions]);
244
+ const usedExtensionTools = useMemo(() => {
245
+ const list = [];
246
+ traverseReactEltTree(componentProps == null ? void 0 : componentProps.toolbar, (elt) => {
247
+ var _a, _b, _c;
248
+ const ext = (_c = (_b = (_a = elt == null ? void 0 : elt.type) == null ? void 0 : _a.displayName) == null ? void 0 : _b.toLowerCase) == null ? void 0 : _c.call(_b);
249
+ if (ext && ext.includes("toolbar")) {
250
+ list.push(ext.replace("toolbar", ""));
251
+ }
252
+ });
253
+ return list;
254
+ }, [componentProps == null ? void 0 : componentProps.toolbar]);
255
+ const handleChange = (extName, add) => {
256
+ if (add) {
257
+ studioOps.appendToSlot(
258
+ {
259
+ type: "component",
260
+ name: `${TIPTAP_COMPONENT_NAME}-extension-${extName}`,
261
+ props: {}
262
+ },
263
+ "extensions"
264
+ );
265
+ studioOps.appendToSlot(
266
+ {
267
+ type: "component",
268
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-${extName}`,
269
+ props: {}
270
+ },
271
+ "toolbar"
272
+ );
273
+ } else {
274
+ const extIndices = usedExtensions.flatMap(
275
+ (ext, i) => ext === extName ? i : []
276
+ );
277
+ extIndices.reverse().forEach(
278
+ (i) => i !== -1 && studioOps.removeFromSlotAt(i, "extensions")
279
+ );
280
+ const toolIndices = usedExtensionTools.flatMap(
281
+ (ext, i) => ext === extName ? i : []
282
+ );
283
+ toolIndices.reverse().forEach((i) => i !== -1 && studioOps.removeFromSlotAt(i, "toolbar"));
284
+ }
285
+ };
286
+ return /* @__PURE__ */ React.createElement(
287
+ "div",
288
+ {
289
+ style: {
290
+ marginBottom: 10,
291
+ paddingBottom: 10,
292
+ borderBottom: "1px dashed #ccc"
293
+ }
294
+ },
295
+ /* @__PURE__ */ React.createElement("p", null, "You can add capabilities to Tiptap Rich Text Editor using the tools below."),
296
+ /* @__PURE__ */ React.createElement("p", null, `To further customize the extensions, find them under the Editor's "extensions" and "toolbar" slots`),
297
+ allExtensions.map((ext) => /* @__PURE__ */ React.createElement(
298
+ "label",
299
+ {
300
+ "data-test-id": `custom-action-${ext}`,
301
+ style: {
302
+ display: "flex",
303
+ justifyContent: "space-between",
304
+ marginBottom: 5,
305
+ color: "#1b1b18"
306
+ }
307
+ },
308
+ /* @__PURE__ */ React.createElement("span", null, ext),
309
+ /* @__PURE__ */ React.createElement(
310
+ Switch,
311
+ {
312
+ size: "small",
313
+ checked: usedExtensions.includes(ext) || usedExtensionTools.includes(ext),
314
+ onChange: (checked) => handleChange(ext, checked)
315
+ }
316
+ )
317
+ ))
318
+ );
319
+ }
320
+ function registerTiptap(loader) {
321
+ registerComponentHelper(loader, TiptapWrapper, {
322
+ name: TIPTAP_COMPONENT_NAME,
323
+ displayName: "Tiptap Rich Text Editor",
324
+ defaultStyles: {
325
+ borderWidth: "1px",
326
+ borderStyle: "solid",
327
+ borderColor: "rgb(204,204,204)",
328
+ borderRadius: "4px",
329
+ padding: "10px",
330
+ width: "300px"
331
+ },
332
+ actions: [
333
+ {
334
+ type: "custom-action",
335
+ control: AddExtension
336
+ }
337
+ ],
338
+ props: {
339
+ contentHtml: {
340
+ type: "string",
341
+ displayName: "HTML Content",
342
+ editOnly: true,
343
+ uncontrolledProp: "defaultContentHtml",
344
+ description: "Contents of the editor"
345
+ },
346
+ contentJson: {
347
+ type: "object",
348
+ displayName: "JSON Content",
349
+ hidden: () => true
350
+ },
351
+ extensions: {
352
+ type: "slot",
353
+ hidePlaceholder: true,
354
+ allowedComponents: allExtensions.map(
355
+ (ext) => `${TIPTAP_COMPONENT_NAME}-extension-${ext}`
356
+ )
357
+ },
358
+ toolbar: {
359
+ type: "slot",
360
+ hidePlaceholder: true,
361
+ allowedComponents: allExtensions.map(
362
+ (ext) => `${TIPTAP_COMPONENT_NAME}-toolbar-${ext}`
363
+ )
364
+ },
365
+ onChange: {
366
+ type: "eventHandler",
367
+ argTypes: [{ name: "content", type: "object" }]
368
+ }
369
+ },
370
+ states: {
371
+ content: {
372
+ type: "writable",
373
+ variableType: "object",
374
+ valueProp: "contentJson",
375
+ onChangeProp: "onChange"
376
+ }
377
+ },
378
+ importName: "TiptapWrapper",
379
+ importPath: "@plasmicpkgs/tiptap/skinny/registerTiptap"
380
+ });
381
+ }
382
+
383
+ function Bold(props) {
384
+ const { setBold } = useTiptapContext();
385
+ useEffect(() => {
386
+ setBold(
387
+ TiptapBold.configure({
388
+ HTMLAttributes: {
389
+ class: props.className
390
+ }
391
+ })
392
+ );
393
+ return () => {
394
+ setBold(void 0);
395
+ };
396
+ }, []);
397
+ return null;
398
+ }
399
+ Bold.displayName = "Bold";
400
+ function registerBold(loader) {
401
+ registerComponentHelper(loader, Bold, {
402
+ name: `${TIPTAP_COMPONENT_NAME}-extension-bold`,
403
+ displayName: "Tiptap Bold",
404
+ props: {},
405
+ importName: "Bold",
406
+ importPath: "@plasmicpkgs/tiptap/skinny/registerBold",
407
+ parentComponentName: TIPTAP_COMPONENT_NAME
408
+ });
409
+ }
410
+
411
+ function Code(props) {
412
+ const { setCode } = useTiptapContext();
413
+ useEffect(() => {
414
+ setCode(
415
+ TiptapCode.configure({
416
+ HTMLAttributes: {
417
+ class: props.className
418
+ }
419
+ })
420
+ );
421
+ return () => {
422
+ setCode(void 0);
423
+ };
424
+ }, []);
425
+ return null;
426
+ }
427
+ Code.displayName = "Code";
428
+ function registerCode(loader) {
429
+ registerComponentHelper(loader, Code, {
430
+ name: `${TIPTAP_COMPONENT_NAME}-extension-code`,
431
+ displayName: "Tiptap Code",
432
+ props: {},
433
+ importName: "Code",
434
+ importPath: "@plasmicpkgs/tiptap/skinny/registerCode",
435
+ parentComponentName: TIPTAP_COMPONENT_NAME
436
+ });
437
+ }
438
+
439
+ function Italic(props) {
440
+ const { setItalic } = useTiptapContext();
441
+ useEffect(() => {
442
+ setItalic(
443
+ TiptapItalic.configure({
444
+ HTMLAttributes: {
445
+ class: props.className
446
+ }
447
+ })
448
+ );
449
+ return () => {
450
+ setItalic(void 0);
451
+ };
452
+ }, []);
453
+ return null;
454
+ }
455
+ Italic.displayName = "Italic";
456
+ function registerItalic(loader) {
457
+ registerComponentHelper(loader, Italic, {
458
+ name: `${TIPTAP_COMPONENT_NAME}-extension-italic`,
459
+ displayName: "Tiptap Italic",
460
+ props: {},
461
+ importName: "Italic",
462
+ importPath: "@plasmicpkgs/tiptap/skinny/registerItalic",
463
+ parentComponentName: TIPTAP_COMPONENT_NAME
464
+ });
465
+ }
466
+
467
+ function Link(props) {
468
+ const { setLink } = useTiptapContext();
469
+ useEffect(() => {
470
+ setLink(
471
+ TiptapLink.configure({
472
+ HTMLAttributes: {
473
+ class: props.className
474
+ }
475
+ })
476
+ );
477
+ return () => {
478
+ setLink(void 0);
479
+ };
480
+ }, []);
481
+ return null;
482
+ }
483
+ Link.displayName = "Link";
484
+ function registerLink(loader) {
485
+ registerComponentHelper(loader, Link, {
486
+ name: `${TIPTAP_COMPONENT_NAME}-extension-link`,
487
+ displayName: "Tiptap Link",
488
+ props: {},
489
+ importName: "Link",
490
+ importPath: "@plasmicpkgs/tiptap/skinny/registerLink",
491
+ parentComponentName: TIPTAP_COMPONENT_NAME
492
+ });
493
+ }
494
+
495
+ var MentionList = forwardRef(
496
+ (props, ref) => {
497
+ const [selectedIndex, setSelectedIndex] = useState(0);
498
+ const {
499
+ items = [],
500
+ suggestionItem,
501
+ searchField,
502
+ popupClassName,
503
+ itemClassName,
504
+ selectedItemClassName
505
+ } = props;
506
+ const selectItem = (index) => {
507
+ var _a;
508
+ const item = items[index];
509
+ if (item) {
510
+ (_a = props.command) == null ? void 0 : _a.call(props, { id: item[searchField] });
511
+ }
512
+ };
513
+ const upHandler = () => {
514
+ setSelectedIndex((selectedIndex + (items == null ? void 0 : items.length) - 1) % items.length);
515
+ };
516
+ const downHandler = () => {
517
+ setSelectedIndex((selectedIndex + 1) % items.length);
518
+ };
519
+ const enterHandler = () => {
520
+ selectItem(selectedIndex);
521
+ };
522
+ useEffect(() => setSelectedIndex(0), [items]);
523
+ useImperativeHandle(ref, () => ({
524
+ onKeyDown: (event) => {
525
+ if (event.key === "ArrowUp") {
526
+ upHandler();
527
+ return true;
528
+ }
529
+ if (event.key === "ArrowDown") {
530
+ downHandler();
531
+ return true;
532
+ }
533
+ if (event.key === "Enter") {
534
+ enterHandler();
535
+ return true;
536
+ }
537
+ return false;
538
+ }
539
+ }));
540
+ const css = `
541
+ .SuggestionsList {
542
+ background: #eee;
543
+ position: relative;
544
+ border-radius: 0.5rem;
545
+
546
+ & .item {
547
+ display: block;
548
+ width: 100%;
549
+
550
+ & .is-selected {
551
+ color: purple;
552
+ }
553
+ }
554
+ }
555
+
556
+ `;
557
+ const hasSuggestionItemSlot = suggestionItem == null ? void 0 : suggestionItem.props.children;
558
+ return /* @__PURE__ */ React.createElement("div", { className: `SuggestionsList` }, /* @__PURE__ */ React.createElement("div", { className: popupClassName }, props.items.length ? props.items.map((item, index) => /* @__PURE__ */ React.createElement(
559
+ "div",
560
+ {
561
+ role: "button",
562
+ className: `item`,
563
+ key: index,
564
+ onClick: () => selectItem(index)
565
+ },
566
+ /* @__PURE__ */ React.createElement(
567
+ DataProvider,
568
+ {
569
+ key: item[searchField],
570
+ name: "suggestionItem",
571
+ data: item
572
+ },
573
+ /* @__PURE__ */ React.createElement(
574
+ "div",
575
+ {
576
+ className: `${itemClassName} ${index === selectedIndex ? "is-selected" : ""}`
577
+ },
578
+ /* @__PURE__ */ React.createElement(
579
+ "div",
580
+ {
581
+ className: index === selectedIndex ? selectedItemClassName : ""
582
+ },
583
+ hasSuggestionItemSlot ? repeatedElement(index === 0, suggestionItem) : item[searchField]
584
+ )
585
+ )
586
+ )
587
+ )) : /* @__PURE__ */ React.createElement("div", { className: "item" }, "No result")), /* @__PURE__ */ React.createElement("style", { dangerouslySetInnerHTML: { __html: css } }));
588
+ }
589
+ );
590
+
591
+ var __defProp = Object.defineProperty;
592
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
593
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
594
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
595
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
596
+ var __spreadValues = (a, b) => {
597
+ for (var prop in b || (b = {}))
598
+ if (__hasOwnProp.call(b, prop))
599
+ __defNormalProp(a, prop, b[prop]);
600
+ if (__getOwnPropSymbols)
601
+ for (var prop of __getOwnPropSymbols(b)) {
602
+ if (__propIsEnum.call(b, prop))
603
+ __defNormalProp(a, prop, b[prop]);
604
+ }
605
+ return a;
606
+ };
607
+ function Mention(props) {
608
+ const {
609
+ dataStatic = [],
610
+ dataDynamic,
611
+ hasDataDynamic,
612
+ suggestionItem,
613
+ searchField = "id",
614
+ popupClassName,
615
+ itemClassName,
616
+ selectedItemClassName,
617
+ mentionClassName,
618
+ maxSuggestionCount = 5
619
+ } = props;
620
+ const dataDynamicRef = useRef(dataDynamic);
621
+ const hasDataDynamicRef = useRef(hasDataDynamic);
622
+ const maxSuggestionCountRef = useRef(maxSuggestionCount);
623
+ dataDynamicRef.current = dataDynamic;
624
+ hasDataDynamicRef.current = hasDataDynamic;
625
+ maxSuggestionCountRef.current = maxSuggestionCount;
626
+ const { setMention } = useTiptapContext();
627
+ useEffect(() => {
628
+ setMention(
629
+ TiptapMention.configure({
630
+ HTMLAttributes: {
631
+ class: mentionClassName
632
+ },
633
+ renderLabel: ({ options, node }) => {
634
+ return `${options.suggestion.char}${node.attrs.id}`;
635
+ },
636
+ suggestion: {
637
+ /**
638
+ * This function below only does static filtering. It can't give query parameters to the Plasmic query for filtering at the server side to avoid some complexities.
639
+ *
640
+ * Before we move on to the issues, lets first explain how it could have supported server-side filtering via query params:
641
+ * - The user creates a plasmic query to fetch the suggestions. These suggestions are filtered by some query parameter. The value of the query parameter is bound to the currentMention state.
642
+ *
643
+ * - When the user types `@abc` for example, the following async function `items` is triggered. It knows the query and returns the new set of suggestions. The returned array is rendered in the suggestions popup
644
+ *
645
+ * Issues:
646
+ * 1. Stale Query issue:
647
+ * The same async function is responsible for setting the currentMention state, and also return the new suggestion results. We can't await the Plasmic query after it is triggered by the currentMention state change. So query results it has are stale.
648
+ *
649
+ * Solution: We poll the Plasmic query's isLoading field (indefinitely)
650
+ *
651
+ * For simplicity, therefore, we are just supporting static filtering for now, and may consider the approach highlighted above for filtering via query params.
652
+ *
653
+ * 2. The async function is provided at the time of extension initialization. That async function only knows the state/props in its render cycle, so these props are outdated at the time the async function is triggered.
654
+ *
655
+ * We can't put all of them in the useEffect dependencies array, because change in any of them will cause the Mention extension to be removed/re-added, resulting in a flicker on every keystroke + lost input focus (which causes the suggestion popup to never show)
656
+ *
657
+ * Solution: Use refs
658
+ *
659
+ * @param param0
660
+ * @returns
661
+ */
662
+ items: ({ query }) => {
663
+ var _a, _b;
664
+ if (!query)
665
+ return [];
666
+ if (!hasDataDynamicRef.current) {
667
+ const res = (dataStatic == null ? void 0 : dataStatic.filter(
668
+ (item) => {
669
+ var _a2, _b2, _c;
670
+ return (_c = (_b2 = (_a2 = item[searchField]).toLowerCase) == null ? void 0 : _b2.call(_a2)) == null ? void 0 : _c.includes(query.toLowerCase());
671
+ }
672
+ ).slice(0, maxSuggestionCountRef.current)) || [];
673
+ return res;
674
+ }
675
+ if (!dataDynamicRef.current)
676
+ return [];
677
+ if (((_a = dataDynamicRef.current) == null ? void 0 : _a.isLoading) === false) {
678
+ const data = (_b = dataDynamicRef.current.data) == null ? void 0 : _b.response;
679
+ if (!Array.isArray(data))
680
+ return [];
681
+ return (data == null ? void 0 : data.filter(
682
+ (item) => {
683
+ var _a2, _b2, _c;
684
+ return (_c = (_b2 = (_a2 = item[searchField]).toLowerCase) == null ? void 0 : _b2.call(_a2)) == null ? void 0 : _c.includes(query.toLowerCase());
685
+ }
686
+ ).slice(0, maxSuggestionCountRef.current)) || [];
687
+ }
688
+ return [];
689
+ },
690
+ render: () => {
691
+ let component;
692
+ let popup;
693
+ const otherProps = {
694
+ suggestionItem,
695
+ searchField,
696
+ popupClassName,
697
+ itemClassName,
698
+ selectedItemClassName
699
+ };
700
+ return {
701
+ // eslint-disable-next-line no-shadow
702
+ onStart: (props2) => {
703
+ component = new ReactRenderer(MentionList, {
704
+ props: __spreadValues(__spreadValues({}, props2), otherProps),
705
+ editor: props2.editor
706
+ });
707
+ if (!props2.clientRect) {
708
+ return;
709
+ }
710
+ popup = tippy("body", {
711
+ getReferenceClientRect: props2.clientRect,
712
+ appendTo: () => document.body,
713
+ content: component.element,
714
+ showOnCreate: true,
715
+ interactive: true,
716
+ trigger: "manual",
717
+ placement: "bottom-start"
718
+ });
719
+ },
720
+ // eslint-disable-next-line no-shadow
721
+ onUpdate(props2) {
722
+ var _a;
723
+ component.updateProps(__spreadValues(__spreadValues({}, props2), otherProps));
724
+ if (!props2.clientRect) {
725
+ return;
726
+ }
727
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.setProps({
728
+ getReferenceClientRect: props2.clientRect
729
+ });
730
+ },
731
+ // eslint-disable-next-line no-shadow
732
+ onKeyDown(props2) {
733
+ var _a, _b;
734
+ if (props2.event.key === "Escape") {
735
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.hide();
736
+ return true;
737
+ }
738
+ return ((_b = component.ref) == null ? void 0 : _b.onKeyDown(props2.event)) || false;
739
+ },
740
+ onExit() {
741
+ var _a;
742
+ (_a = popup == null ? void 0 : popup[0]) == null ? void 0 : _a.destroy();
743
+ component.destroy();
744
+ }
745
+ };
746
+ }
747
+ }
748
+ })
749
+ );
750
+ return () => {
751
+ setMention(void 0);
752
+ };
753
+ }, [
754
+ searchField,
755
+ mentionClassName,
756
+ popupClassName,
757
+ itemClassName,
758
+ selectedItemClassName
759
+ ]);
760
+ const inCanvas = !!usePlasmicCanvasContext();
761
+ const providerData = useMemo(() => {
762
+ var _a, _b;
763
+ const noData = [{ [searchField]: "No data" }];
764
+ let data = inCanvas ? noData : [];
765
+ if (!hasDataDynamic) {
766
+ if ((dataStatic == null ? void 0 : dataStatic.length) && Array.isArray(dataStatic)) {
767
+ data = [...dataStatic];
768
+ }
769
+ return data;
770
+ }
771
+ if (!dataDynamic || dataDynamic.isLoading)
772
+ return noData;
773
+ data = (_b = (_a = dataDynamic.data) == null ? void 0 : _a.response) != null ? _b : noData;
774
+ if (!Array.isArray(data))
775
+ return noData;
776
+ return data.slice(0, maxSuggestionCount);
777
+ }, [
778
+ dataDynamic,
779
+ searchField,
780
+ hasDataDynamic,
781
+ maxSuggestionCount,
782
+ dataStatic
783
+ ]);
784
+ return /* @__PURE__ */ React.createElement(
785
+ "div",
786
+ {
787
+ style: __spreadValues({}, {
788
+ // bare minimum styles (that need not be overridden)
789
+ // We just want to make the dataProvider data available to the MentionList component (<DataProvider> is needed to be returned from the returned JSX). It should not be shown in the UI, hence the display: none
790
+ display: "none",
791
+ position: "absolute",
792
+ top: 0,
793
+ background: "white"
794
+ })
795
+ },
796
+ providerData == null ? void 0 : providerData.slice(0, maxSuggestionCount).map((item, index) => {
797
+ var _a;
798
+ return (
799
+ // Data provider needs to be in the returned JSX (the actual use of the "suggestionItem" data is in the MentionList component.)
800
+ /* @__PURE__ */ React.createElement(DataProvider, { key: item.id, name: "suggestionItem", data: item }, (_a = repeatedElement(index === 0, suggestionItem)) != null ? _a : item[searchField])
801
+ );
802
+ })
803
+ );
804
+ }
805
+ Mention.displayName = "Mention";
806
+ function registerMention(loader) {
807
+ registerComponentHelper(loader, Mention, {
808
+ name: `${TIPTAP_COMPONENT_NAME}-extension-mention`,
809
+ displayName: "Tiptap Mention",
810
+ providesData: true,
811
+ props: {
812
+ dataDynamic: {
813
+ type: "dataSourceOpData",
814
+ description: "Filtered suggestions",
815
+ disableDynamicValue: true,
816
+ // we don't want the users to temper with the Plasmic's default query type.
817
+ hidden: (ps) => !ps.hasDataDynamic
818
+ },
819
+ searchField: {
820
+ type: "string",
821
+ defaultValueHint: "id"
822
+ },
823
+ maxSuggestionCount: {
824
+ type: "number",
825
+ defaultValueHint: 5,
826
+ description: "Limits the number of suggestions that appear in the suggestions popup"
827
+ },
828
+ dataStatic: {
829
+ type: "array",
830
+ hidden: (ps) => Boolean(ps.hasDataDynamic),
831
+ itemType: {
832
+ type: "object",
833
+ nameFunc: (item) => item.label,
834
+ fields: {
835
+ id: "string",
836
+ label: "string"
837
+ }
838
+ },
839
+ defaultValue: [
840
+ {
841
+ id: "thomasEd1",
842
+ label: "Thomas Edison"
843
+ },
844
+ {
845
+ id: "sherlock221b",
846
+ label: "Sherlock Holmes"
847
+ },
848
+ {
849
+ id: "eliot_thomas",
850
+ label: "T.S Eliot"
851
+ },
852
+ {
853
+ id: "shakespeare74",
854
+ label: "William Shakespeare"
855
+ }
856
+ ]
857
+ },
858
+ hasDataDynamic: {
859
+ type: "boolean"
860
+ },
861
+ mentionClassName: {
862
+ type: "class",
863
+ displayName: "Mention label"
864
+ },
865
+ popupClassName: {
866
+ type: "class",
867
+ displayName: "Suggestion Popup"
868
+ },
869
+ itemClassName: {
870
+ type: "class",
871
+ displayName: "Suggestion Item"
872
+ },
873
+ selectedItemClassName: {
874
+ type: "class",
875
+ displayName: "Selected Item"
876
+ },
877
+ suggestionItem: {
878
+ type: "slot"
879
+ },
880
+ currentMention: {
881
+ type: "string",
882
+ hidden: () => true
883
+ }
884
+ },
885
+ importName: "Mention",
886
+ importPath: "@plasmicpkgs/tiptap/skinny/registerMention",
887
+ parentComponentName: TIPTAP_COMPONENT_NAME
888
+ });
889
+ }
890
+
891
+ function Strike(props) {
892
+ const { setStrike } = useTiptapContext();
893
+ useEffect(() => {
894
+ setStrike(
895
+ TiptapStrike.configure({
896
+ HTMLAttributes: {
897
+ class: props.className
898
+ }
899
+ })
900
+ );
901
+ return () => {
902
+ setStrike(void 0);
903
+ };
904
+ }, []);
905
+ return null;
906
+ }
907
+ Strike.displayName = "Strike";
908
+ function registerStrike(loader) {
909
+ registerComponentHelper(loader, Strike, {
910
+ name: `${TIPTAP_COMPONENT_NAME}-extension-strike`,
911
+ displayName: "Tiptap Strike",
912
+ props: {},
913
+ importName: "Strike",
914
+ importPath: "@plasmicpkgs/tiptap/skinny/registerStrike",
915
+ parentComponentName: TIPTAP_COMPONENT_NAME
916
+ });
917
+ }
918
+
919
+ function Underline(props) {
920
+ const { setUnderline } = useTiptapContext();
921
+ useEffect(() => {
922
+ setUnderline(
923
+ TiptapUnderline.configure({
924
+ HTMLAttributes: {
925
+ class: props.className
926
+ }
927
+ })
928
+ );
929
+ return () => {
930
+ setUnderline(void 0);
931
+ };
932
+ }, []);
933
+ return null;
934
+ }
935
+ Underline.displayName = "Underline";
936
+ function registerUnderline(loader) {
937
+ registerComponentHelper(loader, Underline, {
938
+ name: `${TIPTAP_COMPONENT_NAME}-extension-underline`,
939
+ displayName: "Tiptap Underline",
940
+ props: {},
941
+ importName: "Underline",
942
+ importPath: "@plasmicpkgs/tiptap/skinny/registerUnderline",
943
+ parentComponentName: TIPTAP_COMPONENT_NAME
944
+ });
945
+ }
946
+
947
+ function ToolbarBold(props) {
948
+ const { editor } = useCurrentEditor();
949
+ const { bold } = useTiptapContext();
950
+ const { className, children, toolbarBoldScopeClassName } = props;
951
+ if (!editor || !bold)
952
+ return null;
953
+ return /* @__PURE__ */ React.createElement(
954
+ "div",
955
+ {
956
+ "data-active": editor.isActive("bold") ? true : false,
957
+ className: `${className} ${toolbarBoldScopeClassName}`,
958
+ style: { cursor: "pointer" },
959
+ role: "button",
960
+ onClick: () => editor.chain().focus().toggleMark("bold").run()
961
+ },
962
+ children
963
+ );
964
+ }
965
+ ToolbarBold.displayName = "ToolbarBold";
966
+ function registerToolbarBold(loader) {
967
+ registerComponentHelper(loader, ToolbarBold, {
968
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-bold`,
969
+ displayName: "Tiptap Bold Toolbar Option",
970
+ defaultStyles: {
971
+ width: "hug",
972
+ padding: "5px"
973
+ },
974
+ props: {
975
+ children: {
976
+ type: "slot",
977
+ hidePlaceholder: true,
978
+ defaultValue: [
979
+ {
980
+ type: "img",
981
+ src: "https://static1.plasmic.app/bold.svg"
982
+ }
983
+ ]
984
+ },
985
+ toolbarBoldScopeClassName: {
986
+ type: "styleScopeClass",
987
+ scopeName: "toolbarBold"
988
+ },
989
+ selectedClassName: {
990
+ type: "class",
991
+ displayName: "Tool Selected",
992
+ selectors: [
993
+ {
994
+ selector: ":toolbarBold[data-active=true]",
995
+ label: "Base"
996
+ }
997
+ ]
998
+ }
999
+ },
1000
+ importName: "ToolbarBold",
1001
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarBold",
1002
+ parentComponentName: TIPTAP_COMPONENT_NAME
1003
+ });
1004
+ }
1005
+
1006
+ function ToolbarCode(props) {
1007
+ const { editor } = useCurrentEditor();
1008
+ const { code } = useTiptapContext();
1009
+ const { className, children, toolbarCodeScopeClassName } = props;
1010
+ if (!editor || !code)
1011
+ return null;
1012
+ return /* @__PURE__ */ React.createElement(
1013
+ "div",
1014
+ {
1015
+ "data-active": editor.isActive("code") ? true : false,
1016
+ className: `${className} ${toolbarCodeScopeClassName}`,
1017
+ style: { cursor: "pointer" },
1018
+ role: "button",
1019
+ onClick: () => editor.chain().focus().toggleMark("code").run()
1020
+ },
1021
+ children
1022
+ );
1023
+ }
1024
+ ToolbarCode.displayName = "ToolbarCode";
1025
+ function registerToolbarCode(loader) {
1026
+ registerComponentHelper(loader, ToolbarCode, {
1027
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-code`,
1028
+ displayName: "Tiptap Code Toolbar Option",
1029
+ defaultStyles: {
1030
+ width: "hug",
1031
+ padding: "5px"
1032
+ },
1033
+ props: {
1034
+ children: {
1035
+ type: "slot",
1036
+ hidePlaceholder: true,
1037
+ defaultValue: [
1038
+ {
1039
+ type: "img",
1040
+ src: "https://static1.plasmic.app/code.svg"
1041
+ }
1042
+ ]
1043
+ },
1044
+ toolbarCodeScopeClassName: {
1045
+ type: "styleScopeClass",
1046
+ scopeName: "toolbarCode"
1047
+ },
1048
+ selectedClassName: {
1049
+ type: "class",
1050
+ displayName: "Tool Selected",
1051
+ selectors: [
1052
+ {
1053
+ selector: ":toolbarCode[data-active=true]",
1054
+ label: "Base"
1055
+ }
1056
+ ]
1057
+ }
1058
+ },
1059
+ importName: "ToolbarCode",
1060
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarCode",
1061
+ parentComponentName: TIPTAP_COMPONENT_NAME
1062
+ });
1063
+ }
1064
+
1065
+ function ToolbarItalic(props) {
1066
+ const { editor } = useCurrentEditor();
1067
+ const { italic } = useTiptapContext();
1068
+ const { className, children, toolbarItalicScopeClassName } = props;
1069
+ if (!editor || !italic)
1070
+ return null;
1071
+ return /* @__PURE__ */ React.createElement(
1072
+ "div",
1073
+ {
1074
+ "data-active": editor.isActive("italic") ? true : false,
1075
+ className: `${className} ${toolbarItalicScopeClassName}`,
1076
+ style: { cursor: "pointer" },
1077
+ role: "button",
1078
+ onClick: () => editor.chain().focus().toggleMark("italic").run()
1079
+ },
1080
+ children
1081
+ );
1082
+ }
1083
+ ToolbarItalic.displayName = "ToolbarItalic";
1084
+ function registerToolbarItalic(loader) {
1085
+ registerComponentHelper(loader, ToolbarItalic, {
1086
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-italic`,
1087
+ displayName: "Tiptap Italic Toolbar Option",
1088
+ defaultStyles: {
1089
+ width: "hug",
1090
+ padding: "5px"
1091
+ },
1092
+ props: {
1093
+ children: {
1094
+ type: "slot",
1095
+ hidePlaceholder: true,
1096
+ defaultValue: [
1097
+ {
1098
+ type: "img",
1099
+ src: "https://static1.plasmic.app/italic.svg",
1100
+ styles: {
1101
+ width: "hug"
1102
+ }
1103
+ }
1104
+ ]
1105
+ },
1106
+ toolbarItalicScopeClassName: {
1107
+ type: "styleScopeClass",
1108
+ scopeName: "toolbarItalic"
1109
+ },
1110
+ selectedClassName: {
1111
+ type: "class",
1112
+ displayName: "Tool Selected",
1113
+ selectors: [
1114
+ {
1115
+ selector: ":toolbarItalic[data-active=true]",
1116
+ label: "Base"
1117
+ }
1118
+ ]
1119
+ }
1120
+ },
1121
+ importName: "ToolbarItalic",
1122
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarItalic",
1123
+ parentComponentName: TIPTAP_COMPONENT_NAME
1124
+ });
1125
+ }
1126
+
1127
+ function ToolbarLink(props) {
1128
+ const { editor } = useCurrentEditor();
1129
+ const { link } = useTiptapContext();
1130
+ const { className, children, toolbarLinkScopeClassName } = props;
1131
+ if (!editor || !link)
1132
+ return null;
1133
+ return /* @__PURE__ */ React.createElement(
1134
+ "div",
1135
+ {
1136
+ "data-active": editor.isActive("link") ? true : false,
1137
+ className: `${className} ${toolbarLinkScopeClassName}`,
1138
+ style: { cursor: "pointer" },
1139
+ role: "button",
1140
+ onClick: () => editor.chain().focus().toggleMark("link").run()
1141
+ },
1142
+ children
1143
+ );
1144
+ }
1145
+ ToolbarLink.displayName = "ToolbarLink";
1146
+ function registerToolbarLink(loader) {
1147
+ registerComponentHelper(loader, ToolbarLink, {
1148
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-link`,
1149
+ displayName: "Tiptap Link Toolbar Option",
1150
+ defaultStyles: {
1151
+ width: "hug",
1152
+ padding: "5px"
1153
+ },
1154
+ props: {
1155
+ children: {
1156
+ type: "slot",
1157
+ hidePlaceholder: true,
1158
+ defaultValue: [
1159
+ {
1160
+ type: "img",
1161
+ src: "https://static1.plasmic.app/link.svg"
1162
+ }
1163
+ ]
1164
+ },
1165
+ toolbarLinkScopeClassName: {
1166
+ type: "styleScopeClass",
1167
+ scopeName: "toolbarLink"
1168
+ },
1169
+ selectedClassName: {
1170
+ type: "class",
1171
+ displayName: "Tool Selected",
1172
+ selectors: [
1173
+ {
1174
+ selector: ":toolbarLink[data-active=true]",
1175
+ label: "Base"
1176
+ }
1177
+ ]
1178
+ }
1179
+ },
1180
+ importName: "ToolbarLink",
1181
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarLink",
1182
+ parentComponentName: TIPTAP_COMPONENT_NAME
1183
+ });
1184
+ }
1185
+
1186
+ function ToolbarMention(props) {
1187
+ const { editor } = useCurrentEditor();
1188
+ const { mention } = useTiptapContext();
1189
+ const { className, children, toolbarMentionScopeClassName } = props;
1190
+ if (!editor || !mention)
1191
+ return null;
1192
+ return /* @__PURE__ */ React.createElement(
1193
+ "div",
1194
+ {
1195
+ "data-active": editor.isActive("mention") ? true : false,
1196
+ className: `${className} ${toolbarMentionScopeClassName}`,
1197
+ style: { cursor: "pointer" },
1198
+ role: "button",
1199
+ onClick: () => editor.chain().focus().insertContent(" @").run()
1200
+ },
1201
+ children
1202
+ );
1203
+ }
1204
+ ToolbarMention.displayName = "ToolbarMention";
1205
+ function registerToolbarMention(loader) {
1206
+ registerComponentHelper(loader, ToolbarMention, {
1207
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-mention`,
1208
+ displayName: "Tiptap Mention Toolbar Option",
1209
+ defaultStyles: {
1210
+ width: "hug",
1211
+ padding: "5px"
1212
+ },
1213
+ props: {
1214
+ children: {
1215
+ type: "slot",
1216
+ hidePlaceholder: true,
1217
+ defaultValue: [
1218
+ {
1219
+ type: "img",
1220
+ src: "https://static1.plasmic.app/mention.svg"
1221
+ }
1222
+ ]
1223
+ },
1224
+ toolbarMentionScopeClassName: {
1225
+ type: "styleScopeClass",
1226
+ scopeName: "toolbarMention"
1227
+ },
1228
+ selectedClassName: {
1229
+ type: "class",
1230
+ displayName: "Tool Selected",
1231
+ selectors: [
1232
+ {
1233
+ selector: ":toolbarMention[data-active=true]",
1234
+ label: "Base"
1235
+ }
1236
+ ]
1237
+ }
1238
+ },
1239
+ importName: "ToolbarMention",
1240
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarMention",
1241
+ parentComponentName: TIPTAP_COMPONENT_NAME
1242
+ });
1243
+ }
1244
+
1245
+ function ToolbarStrike(props) {
1246
+ const { editor } = useCurrentEditor();
1247
+ const { strike } = useTiptapContext();
1248
+ const { className, children, toolbarStrikeScopeClassName } = props;
1249
+ if (!editor || !strike)
1250
+ return null;
1251
+ return /* @__PURE__ */ React.createElement(
1252
+ "div",
1253
+ {
1254
+ "data-active": editor.isActive("strike") ? true : false,
1255
+ className: `${className} ${toolbarStrikeScopeClassName}`,
1256
+ style: { cursor: "pointer" },
1257
+ role: "button",
1258
+ onClick: () => editor.chain().focus().toggleMark("strike").run()
1259
+ },
1260
+ children
1261
+ );
1262
+ }
1263
+ ToolbarStrike.displayName = "ToolbarStrike";
1264
+ function registerToolbarStrike(loader) {
1265
+ registerComponentHelper(loader, ToolbarStrike, {
1266
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-strike`,
1267
+ displayName: "Tiptap Strike Toolbar Option",
1268
+ defaultStyles: {
1269
+ width: "hug",
1270
+ padding: "5px"
1271
+ },
1272
+ props: {
1273
+ children: {
1274
+ type: "slot",
1275
+ hidePlaceholder: true,
1276
+ defaultValue: [
1277
+ {
1278
+ type: "img",
1279
+ src: "https://static1.plasmic.app/strikethrough.svg"
1280
+ }
1281
+ ]
1282
+ },
1283
+ toolbarStrikeScopeClassName: {
1284
+ type: "styleScopeClass",
1285
+ scopeName: "toolbarStrike"
1286
+ },
1287
+ selectedClassName: {
1288
+ type: "class",
1289
+ displayName: "Tool Selected",
1290
+ selectors: [
1291
+ {
1292
+ selector: ":toolbarStrike[data-active=true]",
1293
+ label: "Base"
1294
+ }
1295
+ ]
1296
+ }
1297
+ },
1298
+ importName: "ToolbarStrike",
1299
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarStrike",
1300
+ parentComponentName: TIPTAP_COMPONENT_NAME
1301
+ });
1302
+ }
1303
+
1304
+ function ToolbarUnderline(props) {
1305
+ const { editor } = useCurrentEditor();
1306
+ const { underline } = useTiptapContext();
1307
+ const { className, children, toolbarUnderlineScopeClassName } = props;
1308
+ if (!editor || !underline)
1309
+ return null;
1310
+ return /* @__PURE__ */ React.createElement(
1311
+ "div",
1312
+ {
1313
+ "data-active": editor.isActive("underline") ? true : false,
1314
+ className: `${className} ${toolbarUnderlineScopeClassName}`,
1315
+ style: { cursor: "pointer" },
1316
+ role: "button",
1317
+ onClick: () => editor.chain().focus().toggleMark("underline").run()
1318
+ },
1319
+ children
1320
+ );
1321
+ }
1322
+ ToolbarUnderline.displayName = "ToolbarUnderline";
1323
+ function registerToolbarUnderline(loader) {
1324
+ registerComponentHelper(loader, ToolbarUnderline, {
1325
+ name: `${TIPTAP_COMPONENT_NAME}-toolbar-underline`,
1326
+ displayName: "Tiptap Underline Toolbar Option",
1327
+ defaultStyles: {
1328
+ width: "hug",
1329
+ padding: "5px"
1330
+ },
1331
+ props: {
1332
+ children: {
1333
+ type: "slot",
1334
+ hidePlaceholder: true,
1335
+ defaultValue: [
1336
+ {
1337
+ type: "img",
1338
+ src: "https://static1.plasmic.app/underline.svg"
1339
+ }
1340
+ ]
1341
+ },
1342
+ toolbarUnderlineScopeClassName: {
1343
+ type: "styleScopeClass",
1344
+ scopeName: "toolbarUnderline"
1345
+ },
1346
+ selectedClassName: {
1347
+ type: "class",
1348
+ displayName: "Tool Selected",
1349
+ selectors: [
1350
+ {
1351
+ selector: ":toolbarUnderline[data-active=true]",
1352
+ label: "Base"
1353
+ }
1354
+ ]
1355
+ }
1356
+ },
1357
+ importName: "ToolbarUnderline",
1358
+ importPath: "@plasmicpkgs/tiptap/skinny/registerToolbarUnderline",
1359
+ parentComponentName: TIPTAP_COMPONENT_NAME
1360
+ });
1361
+ }
1362
+
1363
+ function registerAll(loader) {
1364
+ registerBold(loader);
1365
+ registerCode(loader);
1366
+ registerItalic(loader);
1367
+ registerLink(loader);
1368
+ registerMention(loader);
1369
+ registerStrike(loader);
1370
+ registerTiptap(loader);
1371
+ registerUnderline(loader);
1372
+ registerToolbarBold(loader);
1373
+ registerToolbarCode(loader);
1374
+ registerToolbarItalic(loader);
1375
+ registerToolbarLink(loader);
1376
+ registerToolbarMention(loader);
1377
+ registerToolbarStrike(loader);
1378
+ registerToolbarUnderline(loader);
1379
+ }
1380
+
1381
+ export { registerAll };
1382
+ //# sourceMappingURL=tiptap.esm.js.map