@kedataindo/docflow-core 0.0.84 → 0.0.85
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.cjs +82 -0
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +81 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,6 +60,7 @@ __export(index_exports, {
|
|
|
60
60
|
replaceAll: () => replaceAll,
|
|
61
61
|
replaceCurrent: () => replaceCurrent,
|
|
62
62
|
resolveAction: () => resolveAction,
|
|
63
|
+
sanitizeInlineHTML: () => sanitizeInlineHTML,
|
|
63
64
|
sanitizePastedHTML: () => sanitizePastedHTML,
|
|
64
65
|
searchAndReplaceKey: () => searchAndReplaceKey,
|
|
65
66
|
searchNext: () => searchNext,
|
|
@@ -2112,6 +2113,86 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
|
|
|
2112
2113
|
});
|
|
2113
2114
|
}
|
|
2114
2115
|
|
|
2116
|
+
// src/sanitizeInlineHTML.ts
|
|
2117
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set(["b", "strong", "i", "em", "u", "br"]);
|
|
2118
|
+
var DROP_TAGS = /* @__PURE__ */ new Set([
|
|
2119
|
+
"script",
|
|
2120
|
+
"style",
|
|
2121
|
+
"template",
|
|
2122
|
+
"noscript",
|
|
2123
|
+
"iframe",
|
|
2124
|
+
"frame",
|
|
2125
|
+
"frameset",
|
|
2126
|
+
"object",
|
|
2127
|
+
"embed",
|
|
2128
|
+
"applet",
|
|
2129
|
+
"svg",
|
|
2130
|
+
"math",
|
|
2131
|
+
"link",
|
|
2132
|
+
"meta",
|
|
2133
|
+
"base",
|
|
2134
|
+
"title",
|
|
2135
|
+
"form",
|
|
2136
|
+
"input",
|
|
2137
|
+
"textarea",
|
|
2138
|
+
"select",
|
|
2139
|
+
"button",
|
|
2140
|
+
"canvas",
|
|
2141
|
+
"audio",
|
|
2142
|
+
"video",
|
|
2143
|
+
"source",
|
|
2144
|
+
"track"
|
|
2145
|
+
]);
|
|
2146
|
+
function unwrap2(el) {
|
|
2147
|
+
const parent = el.parentNode;
|
|
2148
|
+
if (!parent) return;
|
|
2149
|
+
while (el.firstChild) parent.insertBefore(el.firstChild, el);
|
|
2150
|
+
parent.removeChild(el);
|
|
2151
|
+
}
|
|
2152
|
+
function stripAttributes(el) {
|
|
2153
|
+
for (const attr of Array.from(el.attributes)) el.removeAttribute(attr.name);
|
|
2154
|
+
}
|
|
2155
|
+
function removeComments2(root) {
|
|
2156
|
+
const doc = root.ownerDocument;
|
|
2157
|
+
if (!doc) return;
|
|
2158
|
+
const walker = doc.createTreeWalker(
|
|
2159
|
+
root,
|
|
2160
|
+
128
|
|
2161
|
+
/* NodeFilter.SHOW_COMMENT */
|
|
2162
|
+
);
|
|
2163
|
+
const comments = [];
|
|
2164
|
+
let node = walker.nextNode();
|
|
2165
|
+
while (node) {
|
|
2166
|
+
comments.push(node);
|
|
2167
|
+
node = walker.nextNode();
|
|
2168
|
+
}
|
|
2169
|
+
for (const comment of comments) comment.parentNode?.removeChild(comment);
|
|
2170
|
+
}
|
|
2171
|
+
function sanitizeInlineHTML(html) {
|
|
2172
|
+
if (!html || typeof html !== "string") return "";
|
|
2173
|
+
if (!html.includes("<")) return html;
|
|
2174
|
+
try {
|
|
2175
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
2176
|
+
removeComments2(doc.body);
|
|
2177
|
+
for (const tag of DROP_TAGS) {
|
|
2178
|
+
for (const el of Array.from(doc.body.getElementsByTagName(tag))) {
|
|
2179
|
+
el.parentNode?.removeChild(el);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
const walk = (node) => {
|
|
2183
|
+
if (node.nodeType !== 1) return;
|
|
2184
|
+
for (const child of Array.from(node.childNodes)) walk(child);
|
|
2185
|
+
const el = node;
|
|
2186
|
+
if (ALLOWED_TAGS.has(el.tagName.toLowerCase())) stripAttributes(el);
|
|
2187
|
+
else unwrap2(el);
|
|
2188
|
+
};
|
|
2189
|
+
for (const child of Array.from(doc.body.childNodes)) walk(child);
|
|
2190
|
+
return doc.body.innerHTML;
|
|
2191
|
+
} catch {
|
|
2192
|
+
return "";
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2115
2196
|
// src/FontSize.ts
|
|
2116
2197
|
var import_core7 = require("@tiptap/core");
|
|
2117
2198
|
function mergeFontSize(textStyleType, existing, fontSize) {
|
|
@@ -2623,6 +2704,7 @@ function openaiCompatibleProvider(config) {
|
|
|
2623
2704
|
replaceAll,
|
|
2624
2705
|
replaceCurrent,
|
|
2625
2706
|
resolveAction,
|
|
2707
|
+
sanitizeInlineHTML,
|
|
2626
2708
|
sanitizePastedHTML,
|
|
2627
2709
|
searchAndReplaceKey,
|
|
2628
2710
|
searchNext,
|
package/dist/index.d.cts
CHANGED
|
@@ -250,6 +250,8 @@ interface DocsEditor {
|
|
|
250
250
|
}
|
|
251
251
|
declare function createEditor(options?: EditorOptions): DocsEditor;
|
|
252
252
|
|
|
253
|
+
declare function sanitizeInlineHTML(html: string): string;
|
|
254
|
+
|
|
253
255
|
interface BlockAttributesOptions {
|
|
254
256
|
pageMap?: () => Map<number, {
|
|
255
257
|
page: number;
|
|
@@ -395,4 +397,4 @@ declare class SubdocumentProvider {
|
|
|
395
397
|
destroy(): void;
|
|
396
398
|
}
|
|
397
399
|
|
|
398
|
-
export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, type DocsEditor, type DocsEditorPlugin, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
|
|
400
|
+
export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, type DocsEditor, type DocsEditorPlugin, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
|
package/dist/index.d.ts
CHANGED
|
@@ -250,6 +250,8 @@ interface DocsEditor {
|
|
|
250
250
|
}
|
|
251
251
|
declare function createEditor(options?: EditorOptions): DocsEditor;
|
|
252
252
|
|
|
253
|
+
declare function sanitizeInlineHTML(html: string): string;
|
|
254
|
+
|
|
253
255
|
interface BlockAttributesOptions {
|
|
254
256
|
pageMap?: () => Map<number, {
|
|
255
257
|
page: number;
|
|
@@ -395,4 +397,4 @@ declare class SubdocumentProvider {
|
|
|
395
397
|
destroy(): void;
|
|
396
398
|
}
|
|
397
399
|
|
|
398
|
-
export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, type DocsEditor, type DocsEditorPlugin, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
|
|
400
|
+
export { AIDraftFn, AIStreamFn, type AwarenessState, BlockAttributesExtension, CitationPort, type ClipboardSource, type CollaborationOptions, type CollaborationSetup, type DocsEditor, type DocsEditorPlugin, EditorContextExtension, type EditorContextOptions, type EditorOptions, FontSizeExtension, ImageUploadHandler, type MonitorMetric, PerformanceMonitor, type PerformanceMonitorOptions, SearchAndReplaceExtension, type SearchMatch, type SearchState, type SlashCommand, type SubdocState, SubdocumentProvider, type SubdocumentProviderOptions, type ToolbarItem, clearSearch, collaborationExtensions, collectExtensions, createActionMap, createCollaboration, createEditor, createPerformanceMonitor, definePlugin, detectClipboardSource, findMatches, getSearchState, normalizeClipboardHTML, replaceAll, replaceCurrent, resolveAction, sanitizeInlineHTML, sanitizePastedHTML, searchAndReplaceKey, searchNext, searchPrev, setSearchQuery };
|
package/dist/index.js
CHANGED
|
@@ -2052,6 +2052,86 @@ function createTiptapEditor(options, plugins, collaborationSetup) {
|
|
|
2052
2052
|
});
|
|
2053
2053
|
}
|
|
2054
2054
|
|
|
2055
|
+
// src/sanitizeInlineHTML.ts
|
|
2056
|
+
var ALLOWED_TAGS = /* @__PURE__ */ new Set(["b", "strong", "i", "em", "u", "br"]);
|
|
2057
|
+
var DROP_TAGS = /* @__PURE__ */ new Set([
|
|
2058
|
+
"script",
|
|
2059
|
+
"style",
|
|
2060
|
+
"template",
|
|
2061
|
+
"noscript",
|
|
2062
|
+
"iframe",
|
|
2063
|
+
"frame",
|
|
2064
|
+
"frameset",
|
|
2065
|
+
"object",
|
|
2066
|
+
"embed",
|
|
2067
|
+
"applet",
|
|
2068
|
+
"svg",
|
|
2069
|
+
"math",
|
|
2070
|
+
"link",
|
|
2071
|
+
"meta",
|
|
2072
|
+
"base",
|
|
2073
|
+
"title",
|
|
2074
|
+
"form",
|
|
2075
|
+
"input",
|
|
2076
|
+
"textarea",
|
|
2077
|
+
"select",
|
|
2078
|
+
"button",
|
|
2079
|
+
"canvas",
|
|
2080
|
+
"audio",
|
|
2081
|
+
"video",
|
|
2082
|
+
"source",
|
|
2083
|
+
"track"
|
|
2084
|
+
]);
|
|
2085
|
+
function unwrap2(el) {
|
|
2086
|
+
const parent = el.parentNode;
|
|
2087
|
+
if (!parent) return;
|
|
2088
|
+
while (el.firstChild) parent.insertBefore(el.firstChild, el);
|
|
2089
|
+
parent.removeChild(el);
|
|
2090
|
+
}
|
|
2091
|
+
function stripAttributes(el) {
|
|
2092
|
+
for (const attr of Array.from(el.attributes)) el.removeAttribute(attr.name);
|
|
2093
|
+
}
|
|
2094
|
+
function removeComments2(root) {
|
|
2095
|
+
const doc = root.ownerDocument;
|
|
2096
|
+
if (!doc) return;
|
|
2097
|
+
const walker = doc.createTreeWalker(
|
|
2098
|
+
root,
|
|
2099
|
+
128
|
|
2100
|
+
/* NodeFilter.SHOW_COMMENT */
|
|
2101
|
+
);
|
|
2102
|
+
const comments = [];
|
|
2103
|
+
let node = walker.nextNode();
|
|
2104
|
+
while (node) {
|
|
2105
|
+
comments.push(node);
|
|
2106
|
+
node = walker.nextNode();
|
|
2107
|
+
}
|
|
2108
|
+
for (const comment of comments) comment.parentNode?.removeChild(comment);
|
|
2109
|
+
}
|
|
2110
|
+
function sanitizeInlineHTML(html) {
|
|
2111
|
+
if (!html || typeof html !== "string") return "";
|
|
2112
|
+
if (!html.includes("<")) return html;
|
|
2113
|
+
try {
|
|
2114
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
2115
|
+
removeComments2(doc.body);
|
|
2116
|
+
for (const tag of DROP_TAGS) {
|
|
2117
|
+
for (const el of Array.from(doc.body.getElementsByTagName(tag))) {
|
|
2118
|
+
el.parentNode?.removeChild(el);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
const walk = (node) => {
|
|
2122
|
+
if (node.nodeType !== 1) return;
|
|
2123
|
+
for (const child of Array.from(node.childNodes)) walk(child);
|
|
2124
|
+
const el = node;
|
|
2125
|
+
if (ALLOWED_TAGS.has(el.tagName.toLowerCase())) stripAttributes(el);
|
|
2126
|
+
else unwrap2(el);
|
|
2127
|
+
};
|
|
2128
|
+
for (const child of Array.from(doc.body.childNodes)) walk(child);
|
|
2129
|
+
return doc.body.innerHTML;
|
|
2130
|
+
} catch {
|
|
2131
|
+
return "";
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2055
2135
|
// src/FontSize.ts
|
|
2056
2136
|
import { Extension as Extension6 } from "@tiptap/core";
|
|
2057
2137
|
function mergeFontSize(textStyleType, existing, fontSize) {
|
|
@@ -2299,6 +2379,7 @@ export {
|
|
|
2299
2379
|
replaceAll,
|
|
2300
2380
|
replaceCurrent,
|
|
2301
2381
|
resolveAction,
|
|
2382
|
+
sanitizeInlineHTML,
|
|
2302
2383
|
sanitizePastedHTML,
|
|
2303
2384
|
searchAndReplaceKey,
|
|
2304
2385
|
searchNext,
|