@meowdown/react 0.25.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -1
- package/dist/index.js +43 -17
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { ExitBoundaryHandler, ImageClickHandler, ImageOptions, LinkClickHandler,
|
|
|
3
3
|
import { SelectionJSON, SelectionJSON as SelectionJSON$1 } from "@prosekit/core";
|
|
4
4
|
import { useEditor, useExtension, useKeymap } from "@prosekit/react";
|
|
5
5
|
|
|
6
|
+
//#region src/utils/date-format.d.ts
|
|
7
|
+
type TimeFormat = '12' | '24';
|
|
8
|
+
//#endregion
|
|
6
9
|
//#region src/components/types.d.ts
|
|
7
10
|
/** A selection to restore: an exact JSON selection, or a document edge. */
|
|
8
11
|
type SelectionHint = SelectionJSON$1 | 'start' | 'end';
|
|
@@ -198,6 +201,11 @@ interface EditorProps {
|
|
|
198
201
|
* to the browser's behavior. Ignored in source mode.
|
|
199
202
|
*/
|
|
200
203
|
spellCheck?: boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Clock format the `/now` slash command inserts: '12' for "3:45pm" or '24'
|
|
206
|
+
* for "15:45". Defaults to '12'. Ignored in source mode.
|
|
207
|
+
*/
|
|
208
|
+
timeFormat?: TimeFormat;
|
|
201
209
|
/** Class on the editable root (the contenteditable). Rich modes only. */
|
|
202
210
|
editorClassName?: string;
|
|
203
211
|
/** Class on the outer `.meowdown` wrapper div. */
|
|
@@ -229,6 +237,7 @@ declare function MeowdownEditor({
|
|
|
229
237
|
placeholder,
|
|
230
238
|
readOnly,
|
|
231
239
|
spellCheck,
|
|
240
|
+
timeFormat,
|
|
232
241
|
editorClassName,
|
|
233
242
|
wrapperClassName,
|
|
234
243
|
handleRef,
|
|
@@ -276,4 +285,4 @@ declare function MarkdownView({
|
|
|
276
285
|
className
|
|
277
286
|
}: MarkdownViewProps): ReactElement;
|
|
278
287
|
//#endregion
|
|
279
|
-
export { type EditorHandle, type EditorMode, type EditorProps, type EditorStateSnapshot, MarkdownView, type MarkdownViewProps, MeowdownEditor, type SelectionHint, type SelectionJSON, type TagItem, type TagSearchHandler, type WikilinkItem, type WikilinkSearchHandler, useEditor, useExtension, useKeymap };
|
|
288
|
+
export { type EditorHandle, type EditorMode, type EditorProps, type EditorStateSnapshot, MarkdownView, type MarkdownViewProps, MeowdownEditor, type SelectionHint, type SelectionJSON, type TagItem, type TagSearchHandler, type TimeFormat, type WikilinkItem, type WikilinkSearchHandler, useEditor, useExtension, useKeymap };
|
package/dist/index.js
CHANGED
|
@@ -656,6 +656,23 @@ function LinkMenu({ onLinkClick, onLinkCopy }) {
|
|
|
656
656
|
return null;
|
|
657
657
|
}
|
|
658
658
|
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/utils/date-format.ts
|
|
661
|
+
/** Formats the current wall-clock time for the `/now` slash command. */
|
|
662
|
+
function formatNowTime(timeFormat) {
|
|
663
|
+
return formatTime(/* @__PURE__ */ new Date(), timeFormat);
|
|
664
|
+
}
|
|
665
|
+
/** Formats a given time as `3:45pm` ('12') or `15:45` ('24'). */
|
|
666
|
+
function formatTime(date, timeFormat) {
|
|
667
|
+
return timeFormat === "12" ? formatTime12(date) : formatTime24(date);
|
|
668
|
+
}
|
|
669
|
+
function formatTime12(date) {
|
|
670
|
+
return `${date.getHours() % 12 || 12}:${date.getMinutes().toString().padStart(2, "0")}${date.getHours() >= 12 ? "pm" : "am"}`;
|
|
671
|
+
}
|
|
672
|
+
function formatTime24(date) {
|
|
673
|
+
return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}`;
|
|
674
|
+
}
|
|
675
|
+
|
|
659
676
|
//#endregion
|
|
660
677
|
//#region src/components/autocomplete-menu.module.css
|
|
661
678
|
var autocomplete_menu_module_default = {
|
|
@@ -676,7 +693,7 @@ function SlashMenuItem({ label, kbd, onSelect }) {
|
|
|
676
693
|
children: [/* @__PURE__ */ jsx("span", { children: label }), kbd && /* @__PURE__ */ jsx("kbd", { children: kbd })]
|
|
677
694
|
});
|
|
678
695
|
}
|
|
679
|
-
function SlashMenu() {
|
|
696
|
+
function SlashMenu({ timeFormat = "12" }) {
|
|
680
697
|
const editor = useEditor$1();
|
|
681
698
|
return /* @__PURE__ */ jsx(AutocompleteRoot, {
|
|
682
699
|
regex: regex$2,
|
|
@@ -744,6 +761,10 @@ function SlashMenu() {
|
|
|
744
761
|
header: true
|
|
745
762
|
})
|
|
746
763
|
}),
|
|
764
|
+
/* @__PURE__ */ jsx(SlashMenuItem, {
|
|
765
|
+
label: "Now",
|
|
766
|
+
onSelect: () => editor.commands.insertText({ text: formatNowTime(timeFormat) })
|
|
767
|
+
}),
|
|
747
768
|
/* @__PURE__ */ jsx(AutocompleteEmpty, {
|
|
748
769
|
className: autocomplete_menu_module_default.Item,
|
|
749
770
|
children: "No results"
|
|
@@ -1060,7 +1081,7 @@ function resolveSelection(doc, selection) {
|
|
|
1060
1081
|
return TextSelection.between(doc.resolve(anchor), doc.resolve(head));
|
|
1061
1082
|
}
|
|
1062
1083
|
}
|
|
1063
|
-
function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onLinkCopy, onTagClick, onExitBoundary, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, ref, children }) {
|
|
1084
|
+
function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onLinkCopy, onTagClick, onExitBoundary, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste, bulletAfterHeading, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, timeFormat, editorClassName, ref, children }) {
|
|
1064
1085
|
const [editor] = useState(() => {
|
|
1065
1086
|
const editor = createEditor({ extension: union(defineEditorExtension(), defineCodeBlockView()) });
|
|
1066
1087
|
if (initialMarkdown) editor.setContent(markdownToDoc(initialMarkdown, {
|
|
@@ -1157,7 +1178,7 @@ function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTa
|
|
|
1157
1178
|
blockHandle && !readOnly && /* @__PURE__ */ jsx(BlockHandle, {}),
|
|
1158
1179
|
!readOnly && /* @__PURE__ */ jsx(TableHandle, {}),
|
|
1159
1180
|
blockHandle && !readOnly && /* @__PURE__ */ jsx(DropIndicator$1, {}),
|
|
1160
|
-
/* @__PURE__ */ jsx(SlashMenu, {}),
|
|
1181
|
+
/* @__PURE__ */ jsx(SlashMenu, { timeFormat }),
|
|
1161
1182
|
!readOnly && /* @__PURE__ */ jsx(LinkMenu, {
|
|
1162
1183
|
onLinkClick,
|
|
1163
1184
|
onLinkCopy
|
|
@@ -1171,7 +1192,7 @@ function ProseKitEditor({ markMode = "focus", initialMarkdown, onDocChange, onTa
|
|
|
1171
1192
|
|
|
1172
1193
|
//#endregion
|
|
1173
1194
|
//#region src/components/editor.tsx
|
|
1174
|
-
function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onLinkCopy, onTagClick, onExitBoundary, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste = true, bulletAfterHeading = false, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, editorClassName, wrapperClassName, handleRef, children }) {
|
|
1195
|
+
function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSearch, onWikilinkSearch, onWikilinkClick, onLinkClick, onLinkCopy, onTagClick, onExitBoundary, resolveImageUrl, onImagePaste, onImageSaveError, onImageClick, embedPaste = true, bulletAfterHeading = false, frontmatter = false, blockHandle = true, placeholder, readOnly, spellCheck, timeFormat, editorClassName, wrapperClassName, handleRef, children }) {
|
|
1175
1196
|
const childRef = useRef(null);
|
|
1176
1197
|
useImperativeHandle(handleRef, () => {
|
|
1177
1198
|
function getMarkdown() {
|
|
@@ -1251,6 +1272,7 @@ function MeowdownEditor({ mode = "focus", initialMarkdown, onDocChange, onTagSea
|
|
|
1251
1272
|
placeholder,
|
|
1252
1273
|
readOnly,
|
|
1253
1274
|
spellCheck,
|
|
1275
|
+
timeFormat,
|
|
1254
1276
|
editorClassName,
|
|
1255
1277
|
children
|
|
1256
1278
|
})
|
|
@@ -1306,18 +1328,22 @@ function outputSpecToReact(spec, content, key = 0) {
|
|
|
1306
1328
|
function WikilinkChip(props) {
|
|
1307
1329
|
const { target, display, onWikilinkClick, children } = props;
|
|
1308
1330
|
return /* @__PURE__ */ jsxs("span", {
|
|
1309
|
-
className: "md-wikilink-view",
|
|
1331
|
+
className: "md-wikilink-view md-atom-view",
|
|
1310
1332
|
children: [/* @__PURE__ */ jsx("span", {
|
|
1311
|
-
className: "md-wikilink-
|
|
1333
|
+
className: "md-wikilink-view-preview md-atom-view-preview",
|
|
1312
1334
|
"data-testid": "wikilink",
|
|
1313
1335
|
contentEditable: false,
|
|
1314
1336
|
onClick: onWikilinkClick ? (event) => onWikilinkClick({
|
|
1315
1337
|
target,
|
|
1316
1338
|
event: event.nativeEvent
|
|
1317
1339
|
}) : void 0,
|
|
1318
|
-
children:
|
|
1340
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
1341
|
+
className: "md-wikilink-view-label",
|
|
1342
|
+
contentEditable: false,
|
|
1343
|
+
children: display || target
|
|
1344
|
+
})
|
|
1319
1345
|
}), /* @__PURE__ */ jsx("span", {
|
|
1320
|
-
className: "md-wikilink-view-content",
|
|
1346
|
+
className: "md-wikilink-view-content md-atom-view-content",
|
|
1321
1347
|
children
|
|
1322
1348
|
})]
|
|
1323
1349
|
});
|
|
@@ -1331,7 +1357,7 @@ function EmbedFrame({ embed }) {
|
|
|
1331
1357
|
return listenForTweetHeight(iframe);
|
|
1332
1358
|
}, [embed.kind, embed.key]);
|
|
1333
1359
|
return /* @__PURE__ */ jsx("span", {
|
|
1334
|
-
className: "md-image-preview md-
|
|
1360
|
+
className: "md-image-view-preview md-atom-view-preview",
|
|
1335
1361
|
contentEditable: false,
|
|
1336
1362
|
children: /* @__PURE__ */ jsx("iframe", {
|
|
1337
1363
|
ref: iframeRef,
|
|
@@ -1354,7 +1380,7 @@ function ImagePreview(props) {
|
|
|
1354
1380
|
const url = (resolveImageUrl ?? defaultResolveImageUrl)(src);
|
|
1355
1381
|
if (!url) return null;
|
|
1356
1382
|
return /* @__PURE__ */ jsx("span", {
|
|
1357
|
-
className: "md-image-preview md-
|
|
1383
|
+
className: "md-image-view-preview md-atom-view-preview",
|
|
1358
1384
|
"data-testid": "image-preview",
|
|
1359
1385
|
contentEditable: false,
|
|
1360
1386
|
children: /* @__PURE__ */ jsx("img", {
|
|
@@ -1372,15 +1398,15 @@ function ImagePreview(props) {
|
|
|
1372
1398
|
function ImageView(props) {
|
|
1373
1399
|
const { src, alt, context, children } = props;
|
|
1374
1400
|
return /* @__PURE__ */ jsxs("span", {
|
|
1375
|
-
className: "md-image-view",
|
|
1376
|
-
children: [/* @__PURE__ */ jsx(
|
|
1377
|
-
className: "md-image-view-content",
|
|
1378
|
-
children
|
|
1379
|
-
}), /* @__PURE__ */ jsx(ImagePreview, {
|
|
1401
|
+
className: "md-image-view md-atom-view",
|
|
1402
|
+
children: [/* @__PURE__ */ jsx(ImagePreview, {
|
|
1380
1403
|
src,
|
|
1381
1404
|
alt,
|
|
1382
1405
|
resolveImageUrl: context.resolveImageUrl,
|
|
1383
1406
|
onImageClick: context.onImageClick
|
|
1407
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
1408
|
+
className: "md-image-view-content md-atom-view-content",
|
|
1409
|
+
children
|
|
1384
1410
|
})]
|
|
1385
1411
|
});
|
|
1386
1412
|
}
|
|
@@ -1430,7 +1456,7 @@ function CodeBlock({ code, language }) {
|
|
|
1430
1456
|
/** Wrap inline `children` in one mark, special-casing the view/link marks. */
|
|
1431
1457
|
function wrapMark(mark, children, context) {
|
|
1432
1458
|
switch (mark.type.name) {
|
|
1433
|
-
case "
|
|
1459
|
+
case "mdWikilink": {
|
|
1434
1460
|
const attrs = mark.attrs;
|
|
1435
1461
|
return /* @__PURE__ */ jsx(WikilinkChip, {
|
|
1436
1462
|
target: attrs.target,
|
|
@@ -1439,7 +1465,7 @@ function wrapMark(mark, children, context) {
|
|
|
1439
1465
|
children
|
|
1440
1466
|
});
|
|
1441
1467
|
}
|
|
1442
|
-
case "
|
|
1468
|
+
case "mdImage": {
|
|
1443
1469
|
const attrs = mark.attrs;
|
|
1444
1470
|
return /* @__PURE__ */ jsx(ImageView, {
|
|
1445
1471
|
src: attrs.src,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meowdown/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.27.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@prosekit/react": "^0.8.0-beta.11",
|
|
31
31
|
"clsx": "^2.1.1",
|
|
32
32
|
"lucide-react": "^1.21.0",
|
|
33
|
-
"@meowdown/core": "0.
|
|
33
|
+
"@meowdown/core": "0.27.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": "^19.0.0",
|