@ctzhian/tiptap 2.5.1 → 2.6.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.
Files changed (35) hide show
  1. package/dist/Editor/demo.js +1 -1
  2. package/dist/EditorMarkdown/index.js +7 -3
  3. package/dist/asset/css/index.css +16 -0
  4. package/dist/component/CustomBubbleMenu/index.js +2 -67
  5. package/dist/component/Icons/{flip-horizontal-2-line-icon.d.ts → flip-grid-icon.d.ts} +1 -1
  6. package/dist/component/Icons/{flip-horizontal-2-line-icon.js → flip-grid-icon.js} +3 -3
  7. package/dist/component/Icons/flip-left-line-icon.d.ts +6 -0
  8. package/dist/component/Icons/flip-left-line-icon.js +13 -0
  9. package/dist/component/Icons/flip-right-line-icon.d.ts +6 -0
  10. package/dist/component/Icons/flip-right-line-icon.js +13 -0
  11. package/dist/component/Icons/index.d.ts +3 -1
  12. package/dist/component/Icons/index.js +3 -1
  13. package/dist/component/Toolbar/EditorInsert/index.js +67 -56
  14. package/dist/contants/enums.d.ts +1 -0
  15. package/dist/contants/enums.js +11 -4
  16. package/dist/contants/markdown-placeholder.d.ts +1 -1
  17. package/dist/contants/markdown-placeholder.js +1 -1
  18. package/dist/contants/slash-commands.js +84 -72
  19. package/dist/extension/component/FlipGrid/ColumnView.d.ts +4 -0
  20. package/dist/extension/component/FlipGrid/ColumnView.js +191 -0
  21. package/dist/extension/component/FlipGrid/index.d.ts +4 -0
  22. package/dist/extension/component/FlipGrid/index.js +284 -0
  23. package/dist/extension/component/FlipGrid/utils.d.ts +24 -0
  24. package/dist/extension/component/FlipGrid/utils.js +180 -0
  25. package/dist/extension/component/SlashCommandsList/index.js +1 -1
  26. package/dist/extension/component/UploadProgress/index.d.ts +1 -1
  27. package/dist/extension/index.js +2 -2
  28. package/dist/extension/node/Alert.js +2 -3
  29. package/dist/extension/node/FileHandler.d.ts +1 -1
  30. package/dist/extension/node/FlipGrid.d.ts +14 -0
  31. package/dist/extension/node/FlipGrid.js +131 -0
  32. package/dist/extension/node/Table.d.ts +1 -1
  33. package/dist/extension/node/index.d.ts +1 -0
  34. package/dist/extension/node/index.js +1 -0
  35. package/package.json +15 -16
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { Extension } from '@tiptap/core';
2
2
  export declare const TableExtension: ({ editable }: {
3
3
  editable: boolean;
4
- }) => (import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any> | Extension<any, any>)[];
4
+ }) => (Extension<any, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableOptions, any> | import("@tiptap/core").Node<import("@tiptap/extension-table").TableHeaderOptions, any>)[];
5
5
  export default TableExtension;
@@ -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,24 +1,10 @@
1
1
  {
2
2
  "name": "@ctzhian/tiptap",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "description": "基于 Tiptap 二次开发的编辑器组件",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
- "scripts": {
9
- "start": "npm run dev",
10
- "dev": "dumi dev",
11
- "build": "rm -rf dist && father build",
12
- "build:watch": "father dev",
13
- "docs:build": "dumi build",
14
- "docs:preview": "dumi preview",
15
- "prepare": "husky install && dumi setup",
16
- "doctor": "father doctor",
17
- "lint": "npm run lint:es && npm run lint:css",
18
- "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
19
- "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
20
- "pre": "pnpm build && pnpm link --global"
21
- },
22
8
  "authors": [
23
9
  "ky.kyy@qq.com"
24
10
  ],
@@ -142,5 +128,18 @@
142
128
  "react-image-crop": "^11.0.10",
143
129
  "react-photo-view": "^1.2.7",
144
130
  "uuid": "^11.1.0"
131
+ },
132
+ "scripts": {
133
+ "start": "npm run dev",
134
+ "dev": "dumi dev",
135
+ "build": "rm -rf dist && father build",
136
+ "build:watch": "father dev",
137
+ "docs:build": "dumi build",
138
+ "docs:preview": "dumi preview",
139
+ "doctor": "father doctor",
140
+ "lint": "npm run lint:es && npm run lint:css",
141
+ "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
142
+ "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
143
+ "pre": "pnpm build && pnpm link --global"
145
144
  }
146
- }
145
+ }