@ibodr/draw 0.2.21 → 0.2.23
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.mjs +34 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -3,11 +3,12 @@ export * from '@ibodr/editor';
|
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import * as React4 from 'react';
|
|
5
5
|
import React4__default, { createContext, forwardRef, useRef, useContext, useEffect, memo, cloneElement, useLayoutEffect, useState, useCallback, useMemo } from 'react';
|
|
6
|
-
import { Extension, getMarkRange, extensions,
|
|
6
|
+
import { Extension, getMarkRange, extensions, getHTMLFromFragment, getText, getSchema, getTextSerializersFromSchema, generateJSON } from '@tiptap/core';
|
|
7
7
|
export { Extension, Mark, Node, getSchema, mergeAttributes } from '@tiptap/core';
|
|
8
8
|
import { Code } from '@tiptap/extension-code';
|
|
9
9
|
import { Highlight } from '@tiptap/extension-highlight';
|
|
10
10
|
import { Typography } from '@tiptap/extension-typography';
|
|
11
|
+
import { Node } from '@tiptap/pm/model';
|
|
11
12
|
import { StarterKit } from '@tiptap/starter-kit';
|
|
12
13
|
import { Plugin, PluginKey, AllSelection, Selection, TextSelection } from '@tiptap/pm/state';
|
|
13
14
|
import classNames3 from 'classnames';
|
|
@@ -2904,22 +2905,35 @@ function getTipTapDefaultExtensions(starterKitOptions) {
|
|
|
2904
2905
|
];
|
|
2905
2906
|
}
|
|
2906
2907
|
var tipTapDefaultExtensions = getTipTapDefaultExtensions();
|
|
2907
|
-
var
|
|
2908
|
+
var serializers = new WeakCache();
|
|
2909
|
+
function createSerializers(extensions2) {
|
|
2910
|
+
const schema = getSchema(extensions2);
|
|
2911
|
+
return {
|
|
2912
|
+
schema,
|
|
2913
|
+
textSerializers: getTextSerializersFromSchema(schema),
|
|
2914
|
+
html: new WeakCache(),
|
|
2915
|
+
text: new WeakCache()
|
|
2916
|
+
};
|
|
2917
|
+
}
|
|
2918
|
+
function getSerializers(extensions2) {
|
|
2919
|
+
return serializers.get(extensions2, () => createSerializers(extensions2));
|
|
2920
|
+
}
|
|
2908
2921
|
function renderHtmlFromRichTextWithExtensions(richText, extensions2) {
|
|
2909
|
-
const
|
|
2922
|
+
const { schema } = getSerializers(extensions2);
|
|
2923
|
+
const html = getHTMLFromFragment(Node.fromJSON(schema, richText).content, schema);
|
|
2910
2924
|
return html.replace(/<p([^>]*)><\/p>/g, "<p$1><br /></p>");
|
|
2911
2925
|
}
|
|
2912
2926
|
function renderHtmlFromRichText(editor, richText) {
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2927
|
+
const extensions2 = editor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions;
|
|
2928
|
+
return getSerializers(extensions2).html.get(
|
|
2929
|
+
richText,
|
|
2930
|
+
() => renderHtmlFromRichTextWithExtensions(richText, extensions2)
|
|
2931
|
+
);
|
|
2917
2932
|
}
|
|
2918
2933
|
function renderHtmlFromRichTextForMeasurement(editor, richText) {
|
|
2919
2934
|
const html = renderHtmlFromRichText(editor, richText);
|
|
2920
2935
|
return `<div class="dr-rich-text">${html}</div>`;
|
|
2921
2936
|
}
|
|
2922
|
-
var plainTextFromRichTextCache = new WeakCache();
|
|
2923
2937
|
function isEmptyRichText(richText) {
|
|
2924
2938
|
if (richText.content.length === 0) return true;
|
|
2925
2939
|
if (richText.content.length === 1) {
|
|
@@ -2934,12 +2948,15 @@ function isEditingRichTextList(editor) {
|
|
|
2934
2948
|
}
|
|
2935
2949
|
function renderPlaintextFromRichText(editor, richText) {
|
|
2936
2950
|
if (isEmptyRichText(richText)) return "";
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2951
|
+
const extensions2 = editor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions;
|
|
2952
|
+
const serializer = getSerializers(extensions2);
|
|
2953
|
+
return serializer.text.get(
|
|
2954
|
+
richText,
|
|
2955
|
+
() => getText(Node.fromJSON(serializer.schema, richText), {
|
|
2956
|
+
blockSeparator: "\n",
|
|
2957
|
+
textSerializers: serializer.textSerializers
|
|
2958
|
+
})
|
|
2959
|
+
);
|
|
2943
2960
|
}
|
|
2944
2961
|
function renderRichTextFromHTML(editor, html) {
|
|
2945
2962
|
const tipTapExtensions = editor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions;
|
|
@@ -8992,8 +9009,8 @@ function copyAs(editor, ids, opts) {
|
|
|
8992
9009
|
exhaustiveSwitchError(opts.format);
|
|
8993
9010
|
}
|
|
8994
9011
|
}
|
|
8995
|
-
async function fallbackWriteTextAsync(
|
|
8996
|
-
await navigator.clipboard?.writeText?.(await
|
|
9012
|
+
async function fallbackWriteTextAsync(getText2) {
|
|
9013
|
+
await navigator.clipboard?.writeText?.(await getText2());
|
|
8997
9014
|
}
|
|
8998
9015
|
|
|
8999
9016
|
// src/lib/ui/hooks/useCopyAs.ts
|
|
@@ -40247,7 +40264,7 @@ init_sanitizeSvg();
|
|
|
40247
40264
|
// src/index.ts
|
|
40248
40265
|
registerDrawLibraryVersion(
|
|
40249
40266
|
"@ibodr/draw",
|
|
40250
|
-
"0.2.
|
|
40267
|
+
"0.2.23",
|
|
40251
40268
|
"esm"
|
|
40252
40269
|
);
|
|
40253
40270
|
/*!
|