@ctzhian/tiptap 2.5.2 → 2.6.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 (30) hide show
  1. package/dist/Editor/demo.js +1 -1
  2. package/dist/asset/css/index.css +16 -0
  3. package/dist/component/CustomBubbleMenu/index.js +1 -1
  4. package/dist/component/Icons/flip-left-line-icon.d.ts +6 -0
  5. package/dist/component/Icons/flip-left-line-icon.js +13 -0
  6. package/dist/component/Icons/flip-right-line-icon.d.ts +6 -0
  7. package/dist/component/Icons/flip-right-line-icon.js +13 -0
  8. package/dist/component/Icons/index.d.ts +2 -0
  9. package/dist/component/Icons/index.js +2 -0
  10. package/dist/component/Toolbar/EditorInsert/index.js +13 -9
  11. package/dist/contants/enums.d.ts +1 -0
  12. package/dist/contants/enums.js +11 -4
  13. package/dist/contants/markdown-placeholder.d.ts +1 -1
  14. package/dist/contants/markdown-placeholder.js +1 -1
  15. package/dist/contants/slash-commands.js +84 -72
  16. package/dist/extension/component/FlipGrid/ColumnView.d.ts +4 -0
  17. package/dist/extension/component/FlipGrid/ColumnView.js +191 -0
  18. package/dist/extension/component/FlipGrid/index.d.ts +4 -0
  19. package/dist/extension/component/FlipGrid/index.js +284 -0
  20. package/dist/extension/component/FlipGrid/utils.d.ts +24 -0
  21. package/dist/extension/component/FlipGrid/utils.js +180 -0
  22. package/dist/extension/component/SlashCommandsList/index.js +1 -1
  23. package/dist/extension/component/UploadProgress/index.d.ts +1 -1
  24. package/dist/extension/index.js +2 -2
  25. package/dist/extension/node/Attachment.js +4 -4
  26. package/dist/extension/node/FlipGrid.d.ts +14 -0
  27. package/dist/extension/node/FlipGrid.js +131 -0
  28. package/dist/extension/node/index.d.ts +1 -0
  29. package/dist/extension/node/index.js +1 -0
  30. package/package.json +1 -2
@@ -0,0 +1,131 @@
1
+ import { mergeAttributes, Node } from '@tiptap/core';
2
+ import { TextSelection } from '@tiptap/pm/state';
3
+ import { ReactNodeViewRenderer } from '@tiptap/react';
4
+ import FlipGridView from "../component/FlipGrid";
5
+ import FlipGridColumnView from "../component/FlipGrid/ColumnView";
6
+ export var MIN_WIDTH = 5;
7
+ export var MAX_COLUMNS = 10;
8
+ export var DEFAULT_GAP = '16px';
9
+ var normalizeWidths = function normalizeWidths(widths) {
10
+ var total = widths.reduce(function (acc, cur) {
11
+ return acc + cur;
12
+ }, 0) || 1;
13
+ return widths.map(function (width) {
14
+ return width / total * 100;
15
+ });
16
+ };
17
+ export var FlipGridColumnExtension = Node.create({
18
+ name: 'flipGridColumn',
19
+ content: 'block+',
20
+ isolating: true,
21
+ defining: true,
22
+ addAttributes: function addAttributes() {
23
+ return {
24
+ width: {
25
+ default: 50,
26
+ parseHTML: function parseHTML(element) {
27
+ var _element$style$width;
28
+ var value = Number(element.getAttribute('data-width') || ((_element$style$width = element.style.width) === null || _element$style$width === void 0 ? void 0 : _element$style$width.replace('%', '')));
29
+ if (Number.isFinite(value)) return value;
30
+ return 50;
31
+ },
32
+ renderHTML: function renderHTML(attributes) {
33
+ var width = Number(attributes.width) || 50;
34
+ return {
35
+ 'data-width': width,
36
+ style: "width: ".concat(width, "%;")
37
+ };
38
+ }
39
+ }
40
+ };
41
+ },
42
+ parseHTML: function parseHTML() {
43
+ return [{
44
+ tag: 'div[data-type="flip-grid-column"]'
45
+ }];
46
+ },
47
+ renderHTML: function renderHTML(_ref) {
48
+ var HTMLAttributes = _ref.HTMLAttributes;
49
+ return ['div', mergeAttributes({
50
+ 'data-type': 'flip-grid-column'
51
+ }, this.options.HTMLAttributes, HTMLAttributes), 0];
52
+ },
53
+ addNodeView: function addNodeView() {
54
+ return ReactNodeViewRenderer(FlipGridColumnView);
55
+ }
56
+ });
57
+ export var FlipGridExtension = Node.create({
58
+ name: 'flipGrid',
59
+ group: 'block',
60
+ content: 'flipGridColumn{2,10}',
61
+ isolating: true,
62
+ defining: true,
63
+ addOptions: function addOptions() {
64
+ return {
65
+ HTMLAttributes: {
66
+ class: 'flip-grid'
67
+ }
68
+ };
69
+ },
70
+ parseHTML: function parseHTML() {
71
+ return [{
72
+ tag: 'div[data-type="flip-grid"]'
73
+ }];
74
+ },
75
+ renderHTML: function renderHTML(_ref2) {
76
+ var HTMLAttributes = _ref2.HTMLAttributes;
77
+ return ['div', mergeAttributes({
78
+ 'data-type': 'flip-grid'
79
+ }, this.options.HTMLAttributes, HTMLAttributes), 0];
80
+ },
81
+ addCommands: function addCommands() {
82
+ return {
83
+ setFlipGrid: function setFlipGrid() {
84
+ var columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2;
85
+ return function (_ref3) {
86
+ var state = _ref3.state,
87
+ dispatch = _ref3.dispatch;
88
+ var columnCount = Math.max(2, Math.min(MAX_COLUMNS, Math.floor(columns)));
89
+ var widths = normalizeWidths(new Array(columnCount).fill(1));
90
+ var schema = state.schema,
91
+ selection = state.selection;
92
+ var gridType = schema.nodes.flipGrid;
93
+ var colType = schema.nodes.flipGridColumn;
94
+ var paraType = schema.nodes.paragraph;
95
+ if (!gridType || !colType || !paraType) return false;
96
+ var gridNode = gridType.create({}, widths.map(function (width) {
97
+ return colType.create({
98
+ width: width
99
+ }, paraType.createAndFill());
100
+ }));
101
+ var tr = state.tr.replaceSelectionWith(gridNode, false);
102
+ var $from = tr.selection.$from;
103
+ var tryResolveGridStart = function tryResolveGridStart() {
104
+ var _$prev$nodeAfter, _$prev$nodeBefore, _$prev$nodeBefore2;
105
+ var after = $from.nodeAfter;
106
+ if ((after === null || after === void 0 ? void 0 : after.type) === gridType) return $from.pos;
107
+ var before = $from.nodeBefore;
108
+ if ((before === null || before === void 0 ? void 0 : before.type) === gridType) return $from.pos - before.nodeSize;
109
+ var $prev = tr.doc.resolve(Math.max(0, $from.pos - 1));
110
+ if (((_$prev$nodeAfter = $prev.nodeAfter) === null || _$prev$nodeAfter === void 0 ? void 0 : _$prev$nodeAfter.type) === gridType) return $prev.pos;
111
+ if (((_$prev$nodeBefore = $prev.nodeBefore) === null || _$prev$nodeBefore === void 0 ? void 0 : _$prev$nodeBefore.type) === gridType) return $prev.pos - (((_$prev$nodeBefore2 = $prev.nodeBefore) === null || _$prev$nodeBefore2 === void 0 ? void 0 : _$prev$nodeBefore2.nodeSize) || 0);
112
+ return null;
113
+ };
114
+ var gridStart = tryResolveGridStart();
115
+ if (gridStart !== null) {
116
+ var textPos = Math.min(tr.doc.content.size, gridStart + 3);
117
+ tr = tr.setSelection(TextSelection.near(tr.doc.resolve(textPos)));
118
+ }
119
+ if (dispatch) {
120
+ dispatch(tr.scrollIntoView());
121
+ }
122
+ return true;
123
+ };
124
+ }
125
+ };
126
+ },
127
+ addNodeView: function addNodeView() {
128
+ return ReactNodeViewRenderer(FlipGridView);
129
+ }
130
+ });
131
+ export default FlipGridExtension;
@@ -5,6 +5,7 @@ export * from './CodeBlockLowlight';
5
5
  export * from './Details';
6
6
  export * from './Emoji';
7
7
  export * from './FileHandler';
8
+ export * from './FlipGrid';
8
9
  export * from './Flow';
9
10
  export * from './HorizontalRule';
10
11
  export * from './Iframe';
@@ -5,6 +5,7 @@ export * from "./CodeBlockLowlight";
5
5
  export * from "./Details";
6
6
  export * from "./Emoji";
7
7
  export * from "./FileHandler";
8
+ export * from "./FlipGrid";
8
9
  export * from "./Flow";
9
10
  export * from "./HorizontalRule";
10
11
  export * from "./Iframe";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "2.5.2",
3
+ "version": "2.6.1",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -94,7 +94,6 @@
94
94
  "@tiptap/extension-horizontal-rule": "^3.11.1",
95
95
  "@tiptap/extension-image": "^3.11.1",
96
96
  "@tiptap/extension-invisible-characters": "^3.11.1",
97
- "@tiptap/extension-link": "^3.11.1",
98
97
  "@tiptap/extension-list": "^3.11.1",
99
98
  "@tiptap/extension-mathematics": "^3.11.1",
100
99
  "@tiptap/extension-mention": "^3.11.1",