@mache-hangar/lunar-editor-react 0.0.1 → 0.0.3
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/README.md +64 -1
- package/dist/extensions/table/index.cjs +1 -1
- package/dist/extensions/table/index.cjs.map +1 -1
- package/dist/extensions/table/index.js +648 -166
- package/dist/extensions/table/index.js.map +1 -1
- package/dist/extensions/table-ui/index.cjs +2 -0
- package/dist/extensions/table-ui/index.cjs.map +1 -0
- package/dist/extensions/table-ui/index.js +531 -0
- package/dist/extensions/table-ui/index.js.map +1 -0
- package/dist/extensions/table-ui.css +1 -0
- package/dist/extensions/table.css +1 -1
- package/dist/types/extensions/table/cell-drag.d.ts +14 -0
- package/dist/types/extensions/table/commands.d.ts +67 -0
- package/dist/types/extensions/table/grid.d.ts +49 -0
- package/dist/types/extensions/table/index.d.ts +5 -1
- package/dist/types/extensions/table/interaction.d.ts +6 -0
- package/dist/types/extensions/table/selection-state.d.ts +3 -0
- package/dist/types/extensions/table-ui/TableProperties.d.ts +9 -0
- package/dist/types/extensions/table-ui/TableTools.d.ts +14 -0
- package/dist/types/extensions/table-ui/index.d.ts +2 -0
- package/dist/types/extensions/table-ui/useTableOverlay.d.ts +24 -0
- package/package.json +23 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
.lunar-editor__document .lunar-table-scroll{position:relative;box-sizing:border-box;width:100%;max-width:100%;overflow-x:auto;overflow-y:hidden}.lunar-editor__document .lunar-table-scroll--fixed>table>:is(thead,tbody,tfoot)>tr>:is(td,th),.lunar-editor__document .lunar-table-scroll--fixed>table>tr>:is(td,th){min-width:0;max-width:none}.lunar-editor__document .lunar-table-resize-controls{position:absolute;inset:0;pointer-events:none}.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls,.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls>.lunar-table-column-handle{box-sizing:border-box;margin:0;padding:0;border:0;min-width:0;min-height:0}.lunar-editor__document[contenteditable=false] .lunar-table-resize-controls{display:none}.lunar-editor__document .lunar-table-column-handle{position:absolute;z-index:3;width:10px;transform:translateX(-50%);cursor:col-resize;touch-action:none;pointer-events:auto;outline:none}.lunar-editor__document .lunar-table-column-handle::after{content:"";position:absolute;top:0;bottom:0;left:4px;width:2px;background:#7b83df;opacity:0}.lunar-editor__document .lunar-table-column-handle:hover::after,.lunar-editor__document .lunar-table-column-handle:focus-visible::after,.lunar-editor__document .lunar-table-column-handle--active::after{opacity:1;width:3px}.lunar-editor__document .lunar-table-scroll--resizing{cursor:col-resize;user-select:none}.lunar-editor__document .lunar-table-scroll--resizing .lunar-table-column-handle:not(.lunar-table-column-handle--active)::after{opacity:0}.lunar-editor__document div>.lunar-table-scroll{width:calc(100% - 24px)}.lunar-editor__document table{display:table;width:max-content;min-width:
|
|
1
|
+
.lunar-editor__document .lunar-table-scroll{position:relative;box-sizing:border-box;width:100%;max-width:100%;overflow-x:auto;overflow-y:hidden}.lunar-editor__document .lunar-table-scroll--fixed>table>:is(thead,tbody,tfoot)>tr>:is(td,th),.lunar-editor__document .lunar-table-scroll--fixed>table>tr>:is(td,th){min-width:0;max-width:none}.lunar-editor__document .lunar-table-resize-controls{position:absolute;inset:0;pointer-events:none}.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls,.lunar-editor__document .lunar-table-scroll>.lunar-table-resize-controls>.lunar-table-column-handle{box-sizing:border-box;margin:0;padding:0;border:0;min-width:0;min-height:0}.lunar-editor__document[contenteditable=false] .lunar-table-resize-controls{display:none}.lunar-editor__document .lunar-table-column-handle{position:absolute;z-index:3;width:10px;transform:translateX(-50%);cursor:col-resize;touch-action:none;pointer-events:auto;outline:none}.lunar-editor__document .lunar-table-column-handle::after{content:"";position:absolute;top:0;bottom:0;left:4px;width:2px;background:#7b83df;opacity:0}.lunar-editor__document .lunar-table-column-handle:hover::after,.lunar-editor__document .lunar-table-column-handle:focus-visible::after,.lunar-editor__document .lunar-table-column-handle--active::after{opacity:1;width:3px}.lunar-editor__document .lunar-table-scroll--resizing{cursor:col-resize;user-select:none}.lunar-editor__document .lunar-table-scroll--resizing .lunar-table-column-handle:not(.lunar-table-column-handle--active)::after{opacity:0}.lunar-editor__document div>.lunar-table-scroll{width:calc(100% - 24px)}.lunar-editor__document table{display:table;width:max-content;min-width:0;max-width:none;box-sizing:border-box;margin:0;color:inherit;border:1px solid #c8cdd2;border-collapse:collapse;border-spacing:0;table-layout:auto}.lunar-editor__document table td,.lunar-editor__document table th{position:relative;min-width:120px;max-width:350px;box-sizing:border-box;padding:10px;color:inherit;border:1px solid #c8cdd2;line-height:1.7;overflow-wrap:anywhere;vertical-align:top;white-space:normal;word-break:normal}.lunar-editor__document table td>*,.lunar-editor__document table th>*{margin:0;padding:0;border:0;line-height:inherit;overflow-wrap:inherit;white-space:inherit}.lunar-editor__document table td p,.lunar-editor__document table th p{border-left:none}.lunar-editor__document table th{background:rgba(0,0,0,.05);font-weight:600;letter-spacing:.05em;text-align:left}.lunar-editor__document table td{border-bottom-color:#c8cdd2}.lunar-editor__document .lunar-table-cell--selected::after{content:"";position:absolute;inset:0;background:rgba(102,126,234,.18);box-shadow:inset 0 0 0 2px rgba(102,126,234,.65);pointer-events:none}.lunar-editor__document .lunar-table-cell--selected::selection,.lunar-editor__document .lunar-table-cell--selected ::selection{background:rgba(0,0,0,0)}.lunar-editor__document.lunar-table-cell-selection::selection,.lunar-editor__document.lunar-table-cell-selection ::selection{background:rgba(0,0,0,0)}.lunar-editor__document.lunar-table-dragging .lunar-table-column-handle{pointer-events:none}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type EditorView } from '@mache-hangar/lunar-editor-core/pm';
|
|
2
|
+
/** One owner per gesture: text within a cell, a bounded rectangle across cells. */
|
|
3
|
+
export declare class CellDragSelection {
|
|
4
|
+
private drag?;
|
|
5
|
+
get active(): boolean;
|
|
6
|
+
start(view: EditorView, event: MouseEvent): boolean;
|
|
7
|
+
cancelIfStale(view: EditorView): void;
|
|
8
|
+
/** Clamp hit-testing to the current table and editor viewport, including on mouseup. */
|
|
9
|
+
private point;
|
|
10
|
+
private move;
|
|
11
|
+
private end;
|
|
12
|
+
cancel: () => void;
|
|
13
|
+
destroy: () => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type EditorState, type EditorView, type Node as PMNode } from '@mache-hangar/lunar-editor-core/pm';
|
|
2
|
+
import { type Cell, type Grid, type Rect } from './grid';
|
|
3
|
+
export type TableAction = 'row_before' | 'row_after' | 'delete_rows' | 'column_before' | 'column_after' | 'delete_columns' | 'delete_table' | 'merge' | 'split' | 'header_row' | 'header_column' | 'caption' | 'clear_cells';
|
|
4
|
+
export type TableCommand = {
|
|
5
|
+
action: TableAction;
|
|
6
|
+
} | {
|
|
7
|
+
action: 'insert';
|
|
8
|
+
rows: number;
|
|
9
|
+
columns: number;
|
|
10
|
+
headerRow?: boolean;
|
|
11
|
+
} | {
|
|
12
|
+
action: 'cell_style';
|
|
13
|
+
textAlign?: 'left' | 'center' | 'right' | 'justify';
|
|
14
|
+
verticalAlign?: 'top' | 'middle' | 'bottom';
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
} | {
|
|
17
|
+
action: 'table_style';
|
|
18
|
+
align?: 'left' | 'center' | 'right';
|
|
19
|
+
width?: '25%' | '50%' | '75%' | '100%';
|
|
20
|
+
};
|
|
21
|
+
export type CellRange = {
|
|
22
|
+
anchor: number;
|
|
23
|
+
head: number;
|
|
24
|
+
dragging?: boolean;
|
|
25
|
+
} | null;
|
|
26
|
+
export type TableState = {
|
|
27
|
+
available: boolean;
|
|
28
|
+
inTable: boolean;
|
|
29
|
+
valid: boolean;
|
|
30
|
+
inCell: boolean;
|
|
31
|
+
rows: number;
|
|
32
|
+
columns: number;
|
|
33
|
+
row: number;
|
|
34
|
+
column: number;
|
|
35
|
+
selectedCells: number;
|
|
36
|
+
canMerge: boolean;
|
|
37
|
+
canSplit: boolean;
|
|
38
|
+
headerRow: boolean;
|
|
39
|
+
headerColumn: boolean;
|
|
40
|
+
caption: boolean;
|
|
41
|
+
textAlign: string;
|
|
42
|
+
verticalAlign: string;
|
|
43
|
+
backgroundColor: string;
|
|
44
|
+
};
|
|
45
|
+
export declare const EMPTY_TABLE_STATE: TableState;
|
|
46
|
+
export declare function tableContext(state: EditorState): {
|
|
47
|
+
table: {
|
|
48
|
+
node: PMNode;
|
|
49
|
+
pos: number;
|
|
50
|
+
};
|
|
51
|
+
grid?: undefined;
|
|
52
|
+
rect?: undefined;
|
|
53
|
+
inCell?: undefined;
|
|
54
|
+
cells?: undefined;
|
|
55
|
+
} | {
|
|
56
|
+
table: {
|
|
57
|
+
node: PMNode;
|
|
58
|
+
pos: number;
|
|
59
|
+
};
|
|
60
|
+
grid: Grid;
|
|
61
|
+
rect: Rect;
|
|
62
|
+
inCell: boolean;
|
|
63
|
+
cells: Cell[];
|
|
64
|
+
} | undefined;
|
|
65
|
+
export declare function getTableState(view: EditorView | undefined): TableState;
|
|
66
|
+
/** All topology commands operate on a logical grid, including rowspan/colspan. */
|
|
67
|
+
export declare function runTableCommand(view: EditorView | undefined, command: TableCommand, text?: string): boolean;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Node as PMNode, type ResolvedPos } from '@mache-hangar/lunar-editor-core/pm';
|
|
2
|
+
export type Cell = {
|
|
3
|
+
node: PMNode;
|
|
4
|
+
row: number;
|
|
5
|
+
col: number;
|
|
6
|
+
rows: number;
|
|
7
|
+
cols: number;
|
|
8
|
+
pos: number;
|
|
9
|
+
};
|
|
10
|
+
export type Row = {
|
|
11
|
+
node: PMNode;
|
|
12
|
+
section: number;
|
|
13
|
+
pos: number;
|
|
14
|
+
};
|
|
15
|
+
export type Grid = {
|
|
16
|
+
node: PMNode;
|
|
17
|
+
pos: number;
|
|
18
|
+
rows: Row[];
|
|
19
|
+
cells: Cell[];
|
|
20
|
+
matrix: Cell[][];
|
|
21
|
+
width: number;
|
|
22
|
+
};
|
|
23
|
+
export type Rect = {
|
|
24
|
+
top: number;
|
|
25
|
+
bottom: number;
|
|
26
|
+
left: number;
|
|
27
|
+
right: number;
|
|
28
|
+
};
|
|
29
|
+
type Column = {
|
|
30
|
+
node: PMNode;
|
|
31
|
+
group: number;
|
|
32
|
+
};
|
|
33
|
+
export declare const isCell: (node: PMNode) => boolean;
|
|
34
|
+
export declare const span: (value: unknown) => number;
|
|
35
|
+
export declare function tableAt(position: ResolvedPos): {
|
|
36
|
+
node: PMNode;
|
|
37
|
+
pos: number;
|
|
38
|
+
} | undefined;
|
|
39
|
+
/** Read the original HTML sections; never flatten thead/tbody/tfoot into a different schema. */
|
|
40
|
+
export declare function readGrid(node: PMNode, pos: number): Grid | undefined;
|
|
41
|
+
export declare function cellAt(grid: Grid, position: number): Cell | undefined;
|
|
42
|
+
/** Expand rectangular selection to include every intersecting merged cell in full. */
|
|
43
|
+
export declare function selectionRect(grid: Grid, anchor: Cell, head: Cell): Rect;
|
|
44
|
+
export declare function intersects(cell: Cell, rect: Rect): boolean;
|
|
45
|
+
export declare function blankCell(template: PMNode, row: number, col: number): Cell;
|
|
46
|
+
/** Rebuild only changed rows/cells and retain all other table children and source identities. */
|
|
47
|
+
export declare function buildTable(grid: Grid, rows: Row[], cells: Cell[], columns?: Column[]): PMNode;
|
|
48
|
+
export declare function editColumns(grid: Grid, at: number, count: number, remove: boolean): Column[] | undefined;
|
|
49
|
+
export {};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { EditorExtension } from '@mache-hangar/lunar-editor-core/extensions';
|
|
2
|
-
|
|
2
|
+
import { type TableExtensionOptions } from './interaction';
|
|
3
|
+
export { EMPTY_TABLE_STATE, getTableState, runTableCommand } from './commands';
|
|
4
|
+
export type { TableAction, TableCommand, TableState } from './commands';
|
|
5
|
+
export type { TableExtensionOptions } from './interaction';
|
|
6
|
+
export declare function createTableExtension(options?: TableExtensionOptions): EditorExtension;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Plugin } from '@mache-hangar/lunar-editor-core/pm';
|
|
2
|
+
import { type CellRange, type TableState } from './commands';
|
|
3
|
+
export type TableExtensionOptions = {
|
|
4
|
+
onStateChange?: (state: TableState) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createTableInteraction(options: TableExtensionOptions): Plugin<CellRange>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableCommand, TableState } from '../table/commands';
|
|
2
|
+
type Props = {
|
|
3
|
+
state: TableState;
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
onCommand: (command: TableCommand) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function CellProperties({ state, disabled, onCommand }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function TableProperties({ state, disabled, onCommand }: Props): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { TableCommand, TableState } from '../table/commands';
|
|
3
|
+
export type TableUiProps = {
|
|
4
|
+
state: TableState;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
onCommand: (command: TableCommand) => void;
|
|
7
|
+
};
|
|
8
|
+
export type TableToolbarProps = TableUiProps & {
|
|
9
|
+
rootRef: RefObject<HTMLElement | null>;
|
|
10
|
+
};
|
|
11
|
+
type Props = TableUiProps;
|
|
12
|
+
export declare function InsertTableButton({ state, disabled, onCommand }: Props): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function TableToolbar({ state, disabled, onCommand, rootRef }: TableToolbarProps): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { TableState } from '../table/commands';
|
|
3
|
+
type Rect = {
|
|
4
|
+
left: number;
|
|
5
|
+
top: number;
|
|
6
|
+
right: number;
|
|
7
|
+
bottom: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
type Overlay = {
|
|
12
|
+
element: HTMLTableElement;
|
|
13
|
+
table: Rect;
|
|
14
|
+
visible: Rect;
|
|
15
|
+
cell?: Rect;
|
|
16
|
+
toolbar: {
|
|
17
|
+
left: number;
|
|
18
|
+
top: number;
|
|
19
|
+
};
|
|
20
|
+
placement: 'above' | 'below' | 'inside';
|
|
21
|
+
};
|
|
22
|
+
/** Presentation only: overlays live outside the editable DOM and never enter exported HTML. */
|
|
23
|
+
export declare function useTableOverlay(rootRef: RefObject<HTMLElement | null>, toolbarRef: RefObject<HTMLDivElement | null>, state: TableState, enabled: boolean): Overlay | null;
|
|
24
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mache-hangar/lunar-editor-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Native React HTML editor components backed by lunar-editor-core",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,13 @@
|
|
|
31
31
|
"import": "./dist/extensions/table/index.js",
|
|
32
32
|
"require": "./dist/extensions/table/index.cjs"
|
|
33
33
|
},
|
|
34
|
-
"./extensions/table.css": "./dist/extensions/table.css"
|
|
34
|
+
"./extensions/table.css": "./dist/extensions/table.css",
|
|
35
|
+
"./extensions/table-ui": {
|
|
36
|
+
"types": "./dist/types/extensions/table-ui/index.d.ts",
|
|
37
|
+
"import": "./dist/extensions/table-ui/index.js",
|
|
38
|
+
"require": "./dist/extensions/table-ui/index.cjs"
|
|
39
|
+
},
|
|
40
|
+
"./extensions/table-ui.css": "./dist/extensions/table-ui.css"
|
|
35
41
|
},
|
|
36
42
|
"files": [
|
|
37
43
|
"dist",
|
|
@@ -39,7 +45,7 @@
|
|
|
39
45
|
],
|
|
40
46
|
"dependencies": {
|
|
41
47
|
"mathlive": "0.110.0",
|
|
42
|
-
"@mache-hangar/lunar-editor-core": "0.0.
|
|
48
|
+
"@mache-hangar/lunar-editor-core": "0.0.2"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
51
|
"jsdom": "^26.1.0",
|
|
@@ -50,11 +56,15 @@
|
|
|
50
56
|
"react-dom": "^19.1.1",
|
|
51
57
|
"sass": "^1.95.0",
|
|
52
58
|
"typescript": "^5.9.3",
|
|
53
|
-
"vite": "^7.2.4"
|
|
59
|
+
"vite": "^7.2.4",
|
|
60
|
+
"antd": "5.29.3",
|
|
61
|
+
"@mache-hangar/components": "0.1.4"
|
|
54
62
|
},
|
|
55
63
|
"peerDependencies": {
|
|
56
64
|
"react": "^18.0.0 || ^19.0.0",
|
|
57
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
|
65
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
66
|
+
"@mache-hangar/components": "^0.1.4",
|
|
67
|
+
"antd": "^5.27.6"
|
|
58
68
|
},
|
|
59
69
|
"license": "MIT",
|
|
60
70
|
"homepage": "https://github.com/felix007-github/web-components/tree/main/packages/lunar-editor-react#readme",
|
|
@@ -70,6 +80,14 @@
|
|
|
70
80
|
"access": "public",
|
|
71
81
|
"registry": "https://registry.npmjs.org/"
|
|
72
82
|
},
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@mache-hangar/components": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"antd": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
73
91
|
"scripts": {
|
|
74
92
|
"build": "vite build && tsc -p tsconfig.json && node scripts/build-styles.cjs",
|
|
75
93
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|