@kopexa/editor-utils 17.0.46 → 17.0.48
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/chunk-23NZ6BRW.mjs +27 -0
- package/dist/chunk-EGCOGZWA.mjs +46 -0
- package/dist/chunk-P55PLOHR.mjs +34 -0
- package/dist/get-selected-nodes-of-type.d.mts +12 -0
- package/dist/get-selected-nodes-of-type.d.ts +12 -0
- package/dist/get-selected-nodes-of-type.js +69 -0
- package/dist/get-selected-nodes-of-type.mjs +7 -0
- package/dist/hooks/use-tiptap-editor.d.mts +20 -0
- package/dist/hooks/use-tiptap-editor.d.ts +20 -0
- package/dist/hooks/use-tiptap-editor.js +58 -0
- package/dist/hooks/use-tiptap-editor.mjs +8 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +103 -3
- package/dist/index.mjs +13 -1
- package/dist/update-node-attrs.d.mts +16 -0
- package/dist/update-node-attrs.d.ts +16 -0
- package/dist/update-node-attrs.js +50 -0
- package/dist/update-node-attrs.mjs +7 -0
- package/package.json +6 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/update-node-attrs.ts
|
|
4
|
+
function updateNodesAttr(tr, targets, attrName, next) {
|
|
5
|
+
if (!targets.length) return false;
|
|
6
|
+
let changed = false;
|
|
7
|
+
for (const { pos } of targets) {
|
|
8
|
+
const currentNode = tr.doc.nodeAt(pos);
|
|
9
|
+
if (!currentNode) continue;
|
|
10
|
+
const prevValue = currentNode.attrs[attrName];
|
|
11
|
+
const resolvedNext = typeof next === "function" ? next(prevValue) : next;
|
|
12
|
+
if (prevValue === resolvedNext) continue;
|
|
13
|
+
const nextAttrs = { ...currentNode.attrs };
|
|
14
|
+
if (resolvedNext === void 0) {
|
|
15
|
+
delete nextAttrs[attrName];
|
|
16
|
+
} else {
|
|
17
|
+
nextAttrs[attrName] = resolvedNext;
|
|
18
|
+
}
|
|
19
|
+
tr.setNodeMarkup(pos, void 0, nextAttrs);
|
|
20
|
+
changed = true;
|
|
21
|
+
}
|
|
22
|
+
return changed;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
updateNodesAttr
|
|
27
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/get-selected-nodes-of-type.ts
|
|
4
|
+
import { NodeSelection } from "@tiptap/pm/state";
|
|
5
|
+
import { CellSelection, cellAround } from "@tiptap/pm/tables";
|
|
6
|
+
import { findParentNodeClosestToPos } from "@tiptap/react";
|
|
7
|
+
function getSelectedNodesOfType(selection, allowedNodeTypes) {
|
|
8
|
+
const results = [];
|
|
9
|
+
const allowed = new Set(allowedNodeTypes);
|
|
10
|
+
if (selection instanceof CellSelection) {
|
|
11
|
+
selection.forEachCell((node, pos) => {
|
|
12
|
+
if (allowed.has(node.type.name)) {
|
|
13
|
+
results.push({ node, pos });
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
if (selection instanceof NodeSelection) {
|
|
19
|
+
const { node, from: pos } = selection;
|
|
20
|
+
if (node && allowed.has(node.type.name)) {
|
|
21
|
+
results.push({ node, pos });
|
|
22
|
+
}
|
|
23
|
+
return results;
|
|
24
|
+
}
|
|
25
|
+
const { $anchor } = selection;
|
|
26
|
+
const cell = cellAround($anchor);
|
|
27
|
+
if (cell) {
|
|
28
|
+
const cellNode = selection.$anchor.doc.nodeAt(cell.pos);
|
|
29
|
+
if (cellNode && allowed.has(cellNode.type.name)) {
|
|
30
|
+
results.push({ node: cellNode, pos: cell.pos });
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const parentNode = findParentNodeClosestToPos(
|
|
35
|
+
$anchor,
|
|
36
|
+
(node) => allowed.has(node.type.name)
|
|
37
|
+
);
|
|
38
|
+
if (parentNode) {
|
|
39
|
+
results.push({ node: parentNode.node, pos: parentNode.pos });
|
|
40
|
+
}
|
|
41
|
+
return results;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
getSelectedNodesOfType
|
|
46
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/hooks/use-tiptap-editor.ts
|
|
4
|
+
import { useCurrentEditor, useEditorState } from "@tiptap/react";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
function useTiptapEditor(providedEditor) {
|
|
7
|
+
const { editor: coreEditor } = useCurrentEditor();
|
|
8
|
+
const mainEditor = useMemo(
|
|
9
|
+
() => providedEditor || coreEditor,
|
|
10
|
+
[providedEditor, coreEditor]
|
|
11
|
+
);
|
|
12
|
+
const editorState = useEditorState({
|
|
13
|
+
editor: mainEditor,
|
|
14
|
+
selector(context) {
|
|
15
|
+
if (!context.editor) {
|
|
16
|
+
return {
|
|
17
|
+
editor: null,
|
|
18
|
+
editorState: void 0,
|
|
19
|
+
canCommand: void 0
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
editor: context.editor,
|
|
24
|
+
editorState: context.editor.state,
|
|
25
|
+
canCommand: context.editor.can
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return editorState || { editor: null };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
useTiptapEditor
|
|
34
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Selection } from '@tiptap/pm/state';
|
|
2
|
+
import { NodeWithPos } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves all nodes of specified types from the current selection.
|
|
6
|
+
* @param selection The current editor selection
|
|
7
|
+
* @param allowedNodeTypes An array of node type names to look for (e.g., ["image", "table"])
|
|
8
|
+
* @returns An array of objects containing the node and its position
|
|
9
|
+
*/
|
|
10
|
+
declare function getSelectedNodesOfType(selection: Selection, allowedNodeTypes: string[]): NodeWithPos[];
|
|
11
|
+
|
|
12
|
+
export { getSelectedNodesOfType };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Selection } from '@tiptap/pm/state';
|
|
2
|
+
import { NodeWithPos } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves all nodes of specified types from the current selection.
|
|
6
|
+
* @param selection The current editor selection
|
|
7
|
+
* @param allowedNodeTypes An array of node type names to look for (e.g., ["image", "table"])
|
|
8
|
+
* @returns An array of objects containing the node and its position
|
|
9
|
+
*/
|
|
10
|
+
declare function getSelectedNodesOfType(selection: Selection, allowedNodeTypes: string[]): NodeWithPos[];
|
|
11
|
+
|
|
12
|
+
export { getSelectedNodesOfType };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/get-selected-nodes-of-type.ts
|
|
22
|
+
var get_selected_nodes_of_type_exports = {};
|
|
23
|
+
__export(get_selected_nodes_of_type_exports, {
|
|
24
|
+
getSelectedNodesOfType: () => getSelectedNodesOfType
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(get_selected_nodes_of_type_exports);
|
|
27
|
+
var import_state = require("@tiptap/pm/state");
|
|
28
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
29
|
+
var import_react = require("@tiptap/react");
|
|
30
|
+
function getSelectedNodesOfType(selection, allowedNodeTypes) {
|
|
31
|
+
const results = [];
|
|
32
|
+
const allowed = new Set(allowedNodeTypes);
|
|
33
|
+
if (selection instanceof import_tables.CellSelection) {
|
|
34
|
+
selection.forEachCell((node, pos) => {
|
|
35
|
+
if (allowed.has(node.type.name)) {
|
|
36
|
+
results.push({ node, pos });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return results;
|
|
40
|
+
}
|
|
41
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
42
|
+
const { node, from: pos } = selection;
|
|
43
|
+
if (node && allowed.has(node.type.name)) {
|
|
44
|
+
results.push({ node, pos });
|
|
45
|
+
}
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
const { $anchor } = selection;
|
|
49
|
+
const cell = (0, import_tables.cellAround)($anchor);
|
|
50
|
+
if (cell) {
|
|
51
|
+
const cellNode = selection.$anchor.doc.nodeAt(cell.pos);
|
|
52
|
+
if (cellNode && allowed.has(cellNode.type.name)) {
|
|
53
|
+
results.push({ node: cellNode, pos: cell.pos });
|
|
54
|
+
return results;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const parentNode = (0, import_react.findParentNodeClosestToPos)(
|
|
58
|
+
$anchor,
|
|
59
|
+
(node) => allowed.has(node.type.name)
|
|
60
|
+
);
|
|
61
|
+
if (parentNode) {
|
|
62
|
+
results.push({ node: parentNode.node, pos: parentNode.pos });
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
getSelectedNodesOfType
|
|
69
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides access to a Tiptap editor instance.
|
|
5
|
+
*
|
|
6
|
+
* Accepts an optional editor instance directly, or falls back to retrieving
|
|
7
|
+
* the editor from the Tiptap context if available. This allows components
|
|
8
|
+
* to work both when given an editor directly and when used within a Tiptap
|
|
9
|
+
* editor context.
|
|
10
|
+
*
|
|
11
|
+
* @param providedEditor - Optional editor instance to use instead of the context editor
|
|
12
|
+
* @returns The provided editor or the editor from context, whichever is available
|
|
13
|
+
*/
|
|
14
|
+
declare function useTiptapEditor(providedEditor?: Editor | null): {
|
|
15
|
+
editor: Editor | null;
|
|
16
|
+
editorState?: Editor["state"];
|
|
17
|
+
canCommand?: Editor["can"];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useTiptapEditor };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook that provides access to a Tiptap editor instance.
|
|
5
|
+
*
|
|
6
|
+
* Accepts an optional editor instance directly, or falls back to retrieving
|
|
7
|
+
* the editor from the Tiptap context if available. This allows components
|
|
8
|
+
* to work both when given an editor directly and when used within a Tiptap
|
|
9
|
+
* editor context.
|
|
10
|
+
*
|
|
11
|
+
* @param providedEditor - Optional editor instance to use instead of the context editor
|
|
12
|
+
* @returns The provided editor or the editor from context, whichever is available
|
|
13
|
+
*/
|
|
14
|
+
declare function useTiptapEditor(providedEditor?: Editor | null): {
|
|
15
|
+
editor: Editor | null;
|
|
16
|
+
editorState?: Editor["state"];
|
|
17
|
+
canCommand?: Editor["can"];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { useTiptapEditor };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
"use client";
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// src/hooks/use-tiptap-editor.ts
|
|
23
|
+
var use_tiptap_editor_exports = {};
|
|
24
|
+
__export(use_tiptap_editor_exports, {
|
|
25
|
+
useTiptapEditor: () => useTiptapEditor
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(use_tiptap_editor_exports);
|
|
28
|
+
var import_react = require("@tiptap/react");
|
|
29
|
+
var import_react2 = require("react");
|
|
30
|
+
function useTiptapEditor(providedEditor) {
|
|
31
|
+
const { editor: coreEditor } = (0, import_react.useCurrentEditor)();
|
|
32
|
+
const mainEditor = (0, import_react2.useMemo)(
|
|
33
|
+
() => providedEditor || coreEditor,
|
|
34
|
+
[providedEditor, coreEditor]
|
|
35
|
+
);
|
|
36
|
+
const editorState = (0, import_react.useEditorState)({
|
|
37
|
+
editor: mainEditor,
|
|
38
|
+
selector(context) {
|
|
39
|
+
if (!context.editor) {
|
|
40
|
+
return {
|
|
41
|
+
editor: null,
|
|
42
|
+
editorState: void 0,
|
|
43
|
+
canCommand: void 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
editor: context.editor,
|
|
48
|
+
editorState: context.editor.state,
|
|
49
|
+
canCommand: context.editor.can
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return editorState || { editor: null };
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
useTiptapEditor
|
|
58
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,9 @@ import * as _tiptap_core from '@tiptap/core';
|
|
|
2
2
|
import { Node, Attrs } from '@tiptap/pm/model';
|
|
3
3
|
import { Selection } from '@tiptap/pm/state';
|
|
4
4
|
import { Editor } from '@tiptap/react';
|
|
5
|
+
export { getSelectedNodesOfType } from './get-selected-nodes-of-type.mjs';
|
|
6
|
+
export { useTiptapEditor } from './hooks/use-tiptap-editor.mjs';
|
|
7
|
+
export { updateNodesAttr } from './update-node-attrs.mjs';
|
|
5
8
|
|
|
6
9
|
type OverflowPosition = "none" | "top" | "bottom" | "both";
|
|
7
10
|
declare function findParentNodeOfType(selection: Selection, typeName: string): {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import * as _tiptap_core from '@tiptap/core';
|
|
|
2
2
|
import { Node, Attrs } from '@tiptap/pm/model';
|
|
3
3
|
import { Selection } from '@tiptap/pm/state';
|
|
4
4
|
import { Editor } from '@tiptap/react';
|
|
5
|
+
export { getSelectedNodesOfType } from './get-selected-nodes-of-type.js';
|
|
6
|
+
export { useTiptapEditor } from './hooks/use-tiptap-editor.js';
|
|
7
|
+
export { updateNodesAttr } from './update-node-attrs.js';
|
|
5
8
|
|
|
6
9
|
type OverflowPosition = "none" | "top" | "bottom" | "both";
|
|
7
10
|
declare function findParentNodeOfType(selection: Selection, typeName: string): {
|
package/dist/index.js
CHANGED
|
@@ -27,16 +27,113 @@ __export(index_exports, {
|
|
|
27
27
|
getActiveMarkAttrs: () => getActiveMarkAttrs,
|
|
28
28
|
getEditorExtension: () => getEditorExtension,
|
|
29
29
|
getElementOverflowPosition: () => getElementOverflowPosition,
|
|
30
|
+
getSelectedNodesOfType: () => getSelectedNodesOfType,
|
|
30
31
|
hasContentAbove: () => hasContentAbove,
|
|
31
32
|
isEmptyNode: () => isEmptyNode,
|
|
32
33
|
isExtensionAvailable: () => isExtensionAvailable,
|
|
33
34
|
isMarkInSchema: () => isMarkInSchema,
|
|
34
35
|
isNodeInSchema: () => isNodeInSchema,
|
|
35
36
|
isNodeTypeSelected: () => isNodeTypeSelected,
|
|
36
|
-
isValidPosition: () => isValidPosition
|
|
37
|
+
isValidPosition: () => isValidPosition,
|
|
38
|
+
updateNodesAttr: () => updateNodesAttr,
|
|
39
|
+
useTiptapEditor: () => useTiptapEditor
|
|
37
40
|
});
|
|
38
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
var import_state2 = require("@tiptap/pm/state");
|
|
43
|
+
|
|
44
|
+
// src/get-selected-nodes-of-type.ts
|
|
39
45
|
var import_state = require("@tiptap/pm/state");
|
|
46
|
+
var import_tables = require("@tiptap/pm/tables");
|
|
47
|
+
var import_react = require("@tiptap/react");
|
|
48
|
+
function getSelectedNodesOfType(selection, allowedNodeTypes) {
|
|
49
|
+
const results = [];
|
|
50
|
+
const allowed = new Set(allowedNodeTypes);
|
|
51
|
+
if (selection instanceof import_tables.CellSelection) {
|
|
52
|
+
selection.forEachCell((node, pos) => {
|
|
53
|
+
if (allowed.has(node.type.name)) {
|
|
54
|
+
results.push({ node, pos });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return results;
|
|
58
|
+
}
|
|
59
|
+
if (selection instanceof import_state.NodeSelection) {
|
|
60
|
+
const { node, from: pos } = selection;
|
|
61
|
+
if (node && allowed.has(node.type.name)) {
|
|
62
|
+
results.push({ node, pos });
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
const { $anchor } = selection;
|
|
67
|
+
const cell = (0, import_tables.cellAround)($anchor);
|
|
68
|
+
if (cell) {
|
|
69
|
+
const cellNode = selection.$anchor.doc.nodeAt(cell.pos);
|
|
70
|
+
if (cellNode && allowed.has(cellNode.type.name)) {
|
|
71
|
+
results.push({ node: cellNode, pos: cell.pos });
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const parentNode = (0, import_react.findParentNodeClosestToPos)(
|
|
76
|
+
$anchor,
|
|
77
|
+
(node) => allowed.has(node.type.name)
|
|
78
|
+
);
|
|
79
|
+
if (parentNode) {
|
|
80
|
+
results.push({ node: parentNode.node, pos: parentNode.pos });
|
|
81
|
+
}
|
|
82
|
+
return results;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// src/hooks/use-tiptap-editor.ts
|
|
86
|
+
var import_react2 = require("@tiptap/react");
|
|
87
|
+
var import_react3 = require("react");
|
|
88
|
+
function useTiptapEditor(providedEditor) {
|
|
89
|
+
const { editor: coreEditor } = (0, import_react2.useCurrentEditor)();
|
|
90
|
+
const mainEditor = (0, import_react3.useMemo)(
|
|
91
|
+
() => providedEditor || coreEditor,
|
|
92
|
+
[providedEditor, coreEditor]
|
|
93
|
+
);
|
|
94
|
+
const editorState = (0, import_react2.useEditorState)({
|
|
95
|
+
editor: mainEditor,
|
|
96
|
+
selector(context) {
|
|
97
|
+
if (!context.editor) {
|
|
98
|
+
return {
|
|
99
|
+
editor: null,
|
|
100
|
+
editorState: void 0,
|
|
101
|
+
canCommand: void 0
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
editor: context.editor,
|
|
106
|
+
editorState: context.editor.state,
|
|
107
|
+
canCommand: context.editor.can
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return editorState || { editor: null };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/update-node-attrs.ts
|
|
115
|
+
function updateNodesAttr(tr, targets, attrName, next) {
|
|
116
|
+
if (!targets.length) return false;
|
|
117
|
+
let changed = false;
|
|
118
|
+
for (const { pos } of targets) {
|
|
119
|
+
const currentNode = tr.doc.nodeAt(pos);
|
|
120
|
+
if (!currentNode) continue;
|
|
121
|
+
const prevValue = currentNode.attrs[attrName];
|
|
122
|
+
const resolvedNext = typeof next === "function" ? next(prevValue) : next;
|
|
123
|
+
if (prevValue === resolvedNext) continue;
|
|
124
|
+
const nextAttrs = { ...currentNode.attrs };
|
|
125
|
+
if (resolvedNext === void 0) {
|
|
126
|
+
delete nextAttrs[attrName];
|
|
127
|
+
} else {
|
|
128
|
+
nextAttrs[attrName] = resolvedNext;
|
|
129
|
+
}
|
|
130
|
+
tr.setNodeMarkup(pos, void 0, nextAttrs);
|
|
131
|
+
changed = true;
|
|
132
|
+
}
|
|
133
|
+
return changed;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// src/index.ts
|
|
40
137
|
function findParentNodeOfType(selection, typeName) {
|
|
41
138
|
let depth = selection.$anchor.depth;
|
|
42
139
|
while (depth > 0) {
|
|
@@ -117,7 +214,7 @@ function isNodeTypeSelected(editor, types = []) {
|
|
|
117
214
|
const { state } = editor;
|
|
118
215
|
const { selection } = state;
|
|
119
216
|
if (selection.empty) return false;
|
|
120
|
-
if (selection instanceof
|
|
217
|
+
if (selection instanceof import_state2.NodeSelection) {
|
|
121
218
|
const node = selection.node;
|
|
122
219
|
return node ? types.includes(node.type.name) : false;
|
|
123
220
|
}
|
|
@@ -184,11 +281,14 @@ function findSelectionPosition(params) {
|
|
|
184
281
|
getActiveMarkAttrs,
|
|
185
282
|
getEditorExtension,
|
|
186
283
|
getElementOverflowPosition,
|
|
284
|
+
getSelectedNodesOfType,
|
|
187
285
|
hasContentAbove,
|
|
188
286
|
isEmptyNode,
|
|
189
287
|
isExtensionAvailable,
|
|
190
288
|
isMarkInSchema,
|
|
191
289
|
isNodeInSchema,
|
|
192
290
|
isNodeTypeSelected,
|
|
193
|
-
isValidPosition
|
|
291
|
+
isValidPosition,
|
|
292
|
+
updateNodesAttr,
|
|
293
|
+
useTiptapEditor
|
|
194
294
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import {
|
|
3
|
+
getSelectedNodesOfType
|
|
4
|
+
} from "./chunk-EGCOGZWA.mjs";
|
|
5
|
+
import {
|
|
6
|
+
updateNodesAttr
|
|
7
|
+
} from "./chunk-23NZ6BRW.mjs";
|
|
8
|
+
import {
|
|
9
|
+
useTiptapEditor
|
|
10
|
+
} from "./chunk-P55PLOHR.mjs";
|
|
2
11
|
|
|
3
12
|
// src/index.ts
|
|
4
13
|
import { NodeSelection } from "@tiptap/pm/state";
|
|
@@ -148,11 +157,14 @@ export {
|
|
|
148
157
|
getActiveMarkAttrs,
|
|
149
158
|
getEditorExtension,
|
|
150
159
|
getElementOverflowPosition,
|
|
160
|
+
getSelectedNodesOfType,
|
|
151
161
|
hasContentAbove,
|
|
152
162
|
isEmptyNode,
|
|
153
163
|
isExtensionAvailable,
|
|
154
164
|
isMarkInSchema,
|
|
155
165
|
isNodeInSchema,
|
|
156
166
|
isNodeTypeSelected,
|
|
157
|
-
isValidPosition
|
|
167
|
+
isValidPosition,
|
|
168
|
+
updateNodesAttr,
|
|
169
|
+
useTiptapEditor
|
|
158
170
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transaction } from '@tiptap/pm/state';
|
|
2
|
+
import { NodeWithPos } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Update a single attribute on multiple nodes.
|
|
6
|
+
*
|
|
7
|
+
* @param tr - The transaction to mutate
|
|
8
|
+
* @param targets - Array of { node, pos }
|
|
9
|
+
* @param attrName - Attribute key to update
|
|
10
|
+
* @param next - New value OR updater function receiving previous value
|
|
11
|
+
* Pass `undefined` to remove the attribute.
|
|
12
|
+
* @returns true if at least one node was updated, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
declare function updateNodesAttr<A extends string = string, V = unknown>(tr: Transaction, targets: readonly NodeWithPos[], attrName: A, next: V | ((prev: V | undefined) => V | undefined)): boolean;
|
|
15
|
+
|
|
16
|
+
export { updateNodesAttr };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transaction } from '@tiptap/pm/state';
|
|
2
|
+
import { NodeWithPos } from '@tiptap/react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Update a single attribute on multiple nodes.
|
|
6
|
+
*
|
|
7
|
+
* @param tr - The transaction to mutate
|
|
8
|
+
* @param targets - Array of { node, pos }
|
|
9
|
+
* @param attrName - Attribute key to update
|
|
10
|
+
* @param next - New value OR updater function receiving previous value
|
|
11
|
+
* Pass `undefined` to remove the attribute.
|
|
12
|
+
* @returns true if at least one node was updated, false otherwise
|
|
13
|
+
*/
|
|
14
|
+
declare function updateNodesAttr<A extends string = string, V = unknown>(tr: Transaction, targets: readonly NodeWithPos[], attrName: A, next: V | ((prev: V | undefined) => V | undefined)): boolean;
|
|
15
|
+
|
|
16
|
+
export { updateNodesAttr };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/update-node-attrs.ts
|
|
22
|
+
var update_node_attrs_exports = {};
|
|
23
|
+
__export(update_node_attrs_exports, {
|
|
24
|
+
updateNodesAttr: () => updateNodesAttr
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(update_node_attrs_exports);
|
|
27
|
+
function updateNodesAttr(tr, targets, attrName, next) {
|
|
28
|
+
if (!targets.length) return false;
|
|
29
|
+
let changed = false;
|
|
30
|
+
for (const { pos } of targets) {
|
|
31
|
+
const currentNode = tr.doc.nodeAt(pos);
|
|
32
|
+
if (!currentNode) continue;
|
|
33
|
+
const prevValue = currentNode.attrs[attrName];
|
|
34
|
+
const resolvedNext = typeof next === "function" ? next(prevValue) : next;
|
|
35
|
+
if (prevValue === resolvedNext) continue;
|
|
36
|
+
const nextAttrs = { ...currentNode.attrs };
|
|
37
|
+
if (resolvedNext === void 0) {
|
|
38
|
+
delete nextAttrs[attrName];
|
|
39
|
+
} else {
|
|
40
|
+
nextAttrs[attrName] = resolvedNext;
|
|
41
|
+
}
|
|
42
|
+
tr.setNodeMarkup(pos, void 0, nextAttrs);
|
|
43
|
+
changed = true;
|
|
44
|
+
}
|
|
45
|
+
return changed;
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
updateNodesAttr
|
|
50
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kopexa/editor-utils",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.48",
|
|
4
4
|
"description": "utility components for our editor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"editor-utils"
|
|
@@ -25,16 +25,16 @@
|
|
|
25
25
|
"url": "https://github.com/kopexa-grc/sight/issues"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
+
"@tiptap/pm": "^3.20.0",
|
|
29
|
+
"@tiptap/react": "^3.20.0",
|
|
28
30
|
"motion": ">=12.23.6",
|
|
29
31
|
"react": ">=19.0.0-rc.0",
|
|
30
32
|
"react-dom": ">=19.0.0-rc.0",
|
|
31
|
-
"@kopexa/theme": "17.22.
|
|
33
|
+
"@kopexa/theme": "17.22.9"
|
|
32
34
|
},
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@kopexa/react-utils": "17.0.46",
|
|
37
|
-
"@kopexa/shared-utils": "17.0.46"
|
|
36
|
+
"@kopexa/react-utils": "17.0.48",
|
|
37
|
+
"@kopexa/shared-utils": "17.0.48"
|
|
38
38
|
},
|
|
39
39
|
"clean-package": "../../../clean-package.config.json",
|
|
40
40
|
"module": "dist/index.mjs",
|