Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 08e1663

Browse files
authored
Merge pull request #37 from trey-wallis/dev
Fix bugs
2 parents 3791765 + 3b5c488 commit 08e1663

File tree

12 files changed

+66
-64
lines changed

12 files changed

+66
-64
lines changed

.github/workflows/release.yml

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ jobs:
2121
id: set-tag-var
2222
run: |
2323
echo "::set-output name=tag::$(git describe --abbrev=0) --tags"
24-
- name: Update version in manifest.json
25-
id: update-version
26-
run: |
27-
sed "s/0\.1\.0/$TAG/" manifest.json
28-
env:
29-
TAG: ${{ steps.vars.outputs.tag }}
3024
# Create the release on github
3125
- name: Create Release
3226
id: create_release

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "notion-like-tables",
33
"name": "Notion-Like Tables",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"minAppVersion": "0.12.0",
66
"description": "Create markdown tables using an interface similar to that found in Notion.so.",
77
"author": "Trey Wallis",

src/app/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import EditableTh from "./components/EditableTh";
1010
import {
1111
initialHeader,
1212
initialCell,
13-
initialHeaderMenuState,
1413
initialRow,
1514
initialTag,
1615
Tag,
@@ -34,7 +33,6 @@ interface Props {
3433
export default function App({ plugin, settings, data }: Props) {
3534
const [oldAppData, setOldAppData] = useState<AppData>(data);
3635
const [appData, setAppData] = useState<AppData>(data);
37-
const [headerMenu, setHeaderMenu] = useState(initialHeaderMenuState);
3836
const appRef = useRef<HTMLInputElement>();
3937

4038
const app = useApp();
@@ -56,7 +54,9 @@ export default function App({ plugin, settings, data }: Props) {
5654
if (DEBUG) console.log("Saving Data");
5755
try {
5856
await saveData(app, oldAppData, appData);
59-
} catch (err) {}
57+
} catch (err) {
58+
console.log(err);
59+
}
6060
}
6161
}
6262
}

src/app/components/DragMenu/index.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import React, { useState, useEffect, useRef } from "react";
1+
import React, { useState, useRef } from "react";
2+
import { v4 as uuidv4 } from "uuid";
23

34
import IconButton from "../IconButton";
45
import Menu from "../Menu";
56

6-
// import DragIndicator from "@mui/icons-material/DragIndicator";
77
import MoreVert from "@mui/icons-material/MoreVert";
88
import DeleteIcon from "@mui/icons-material/Delete";
9-
import { useApp, useForceUpdate } from "../../services/hooks";
109

1110
import IconText from "../IconText";
1211

@@ -23,14 +22,14 @@ export default function DragMenu({ onDeleteClick }: Props) {
2322
isOpen: false,
2423
};
2524
const [clickedButton, setClickedButton] = useState(initialClickedButton);
25+
const [buttonId] = useState(uuidv4());
2626

2727
const buttonRef = useRef<HTMLInputElement>();
2828

2929
function handleOutsideClick(e: MouseEvent | undefined) {
3030
if (e) {
3131
const el = e.target as HTMLInputElement;
32-
console.log(el.nodeName);
33-
if (el.nodeName === "svg" || el.nodeName === "path") return;
32+
if (el.id === buttonId) return;
3433
}
3534
setClickedButton(initialClickedButton);
3635
}
@@ -63,6 +62,7 @@ export default function DragMenu({ onDeleteClick }: Props) {
6362
return (
6463
<div className="NLT__td NLT__hidden-column">
6564
<IconButton
65+
id={buttonId}
6666
icon={<MoreVert />}
6767
ref={buttonRef}
6868
onClick={handleDragClick}

src/app/components/EditableTd/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TagCell from "../TagCell";
66
import ErrorCell from "../ErrorCell";
77
import TagMenuContent from "../TagMenuContent";
88

9-
import { useForceUpdate, useApp } from "../../services/hooks";
9+
import { useForceUpdate } from "../../services/hooks";
1010
import { randomColor } from "../../services/utils";
1111
import { Tag } from "../../services/state";
1212

src/app/components/EditableTh/index.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ export default function EditableTh({
5252
});
5353
}
5454

55-
function handleOutsideClick() {
56-
setHeaderMenu(initialHeaderMenuState);
57-
onSaveClick(id, content);
58-
}
59-
6055
return (
6156
<div className="NLT__header-group" onClick={handleHeaderClick}>
6257
<HeaderMenu
@@ -69,7 +64,7 @@ export default function EditableTh({
6964
content={content}
7065
position={position}
7166
type={type}
72-
onOutsideClick={handleOutsideClick}
67+
onOutsideClick={onSaveClick}
7368
onItemClick={onItemClick}
7469
onDeleteClick={onDeleteClick}
7570
onClose={() => setHeaderMenu(initialHeaderMenuState)}

src/app/components/IconButton/index.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import React, { forwardRef } from "react";
22

33
interface Props {
4+
id?: string;
45
selected?: boolean;
56
icon: React.ReactNode;
67
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
78
}
89

910
const IconButton = forwardRef<HTMLInputElement, Props>(
10-
({ selected = false, icon, onClick }, ref) => {
11+
({ id = "", selected, icon, onClick }, ref) => {
1112
let className = "NLT__button--reset";
1213
if (selected) className += " NLT__selected";
1314

1415
return (
15-
<button className={className} ref={ref} onClick={onClick}>
16+
<button
17+
id={id !== "" ? id : ""}
18+
className={className}
19+
ref={ref}
20+
onClick={onClick}
21+
>
1622
{icon}
1723
</button>
1824
);

src/app/components/TagMenuContent/index.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export default function TagMenuContent({
2727
onTextChange,
2828
onRemoveTagClick,
2929
}: Props) {
30+
function handleTextChange(e: React.ChangeEvent<HTMLInputElement>) {
31+
//Disallow pound
32+
if (e.target.value.match("#")) return;
33+
//Disallow whitespace
34+
if (e.target.value.match(/\s/)) return;
35+
onTextChange(e);
36+
}
37+
3038
function renderSelectableTags() {
3139
const filteredTags = tags.filter((tag: Tag) =>
3240
tag.content.includes(inputText)
@@ -83,7 +91,7 @@ export default function TagMenuContent({
8391
autoFocus
8492
type="text"
8593
value={inputText}
86-
onChange={onTextChange}
94+
onChange={handleTextChange}
8795
/>
8896
</div>
8997
<div className="NLT__tag-menu-bottom">

src/app/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const DEBUG = false;
1+
export const DEBUG = true;
22

33
interface CellType {
44
TEXT: string;

src/app/services/dataUtils/index.tsx

+27-35
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ export const findErrorData = (el: HTMLElement): ErrorData | null => {
2828
const errors: number[] = [];
2929

3030
td.forEach((td, i) => {
31-
let cellType = getCellType(td.textContent, true);
32-
if (cellType === CELL_TYPE.ERROR) {
31+
const cellType = td.textContent;
32+
if (
33+
cellType !== CELL_TYPE.TEXT &&
34+
cellType != CELL_TYPE.NUMBER &&
35+
cellType !== CELL_TYPE.TAG
36+
)
3337
errors.push(i);
34-
}
3538
});
3639

3740
if (errors.length === 0) {
@@ -76,17 +79,11 @@ export const findAppData = (
7679
let cellType = "";
7780
//Set header type based off of the first row's specified cell type
7881
if (i === 1) {
79-
cellType = getCellType(td.textContent, true);
82+
cellType = td.textContent;
8083
headers[j].type = cellType;
8184
return;
8285
} else {
83-
//If empty then just set it to the type it's supposed to be.
84-
//We do this to allow blank cells
85-
if (td.textContent === "") {
86-
cellType = headers[j].type;
87-
} else {
88-
cellType = getCellType(td.textContent, false);
89-
}
86+
cellType = findCellType(td.textContent, headers[j].type);
9087
}
9188

9289
//Check if doesn't match header
@@ -168,7 +165,7 @@ export const loadData = (
168165
el: HTMLElement,
169166
settings: NltSettings
170167
): AppData | ErrorData => {
171-
let data = findErrorData(el);
168+
const data = findErrorData(el);
172169
if (data !== null) {
173170
return data;
174171
} else {
@@ -345,38 +342,33 @@ export const writeContentToDataString = (
345342
return data;
346343
};
347344

348-
export const getCellType = (textContent: string, firstRow: boolean) => {
349-
if (firstRow) {
350-
switch (textContent) {
351-
case CELL_TYPE.TEXT:
352-
return CELL_TYPE.TEXT;
353-
case CELL_TYPE.NUMBER:
354-
return CELL_TYPE.NUMBER;
355-
case CELL_TYPE.TAG:
356-
return CELL_TYPE.TAG;
357-
case CELL_TYPE.MULTI_TAG:
358-
return CELL_TYPE.MULTI_TAG;
359-
default:
360-
return CELL_TYPE.ERROR;
345+
export const findCellType = (textContent: string, expectedType: string) => {
346+
//If empty then just set it to the type it's supposed to be.
347+
//We do this to allow blank cells
348+
if (textContent === "") return expectedType;
349+
350+
const numTags = countNumTags(textContent);
351+
if (numTags === 1) {
352+
//If we have a tag like "#test test" the first will match, but it's technically invalid
353+
if (textContent.match(/\s/)) {
354+
return CELL_TYPE.ERROR;
355+
} else {
356+
return CELL_TYPE.TAG;
361357
}
358+
} else if (numTags > 1) {
359+
return CELL_TYPE.MULTI_TAG;
362360
} else {
363361
if (textContent.match(/^\d+$/)) {
364-
return CELL_TYPE.NUMBER;
362+
if (expectedType === CELL_TYPE.TEXT) return CELL_TYPE.TEXT;
363+
else return CELL_TYPE.NUMBER;
365364
} else {
366-
const numTags = countNumTags(textContent);
367-
if (numTags === 1) {
368-
return CELL_TYPE.TAG;
369-
} else if (numTags > 1) {
370-
return CELL_TYPE.MULTI_TAG;
371-
} else {
372-
return CELL_TYPE.TEXT;
373-
}
365+
return CELL_TYPE.TEXT;
374366
}
375367
}
376368
};
377369

378370
export const countNumTags = (textContent: string): number => {
379-
return (textContent.match(/#\w+/g) || []).length;
371+
return (textContent.match(/#[a-zA-z0-9-_]+/g) || []).length;
380372
};
381373

382374
export const hasLink = (content: string): boolean => {

src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import App from "./app/App.tsx";
44
import "./index.css";
55
import reportWebVitals from "./reportWebVitals";
66

7+
const data = {
8+
headers: [],
9+
rows: [],
10+
cells: [],
11+
tags: [],
12+
};
713
//This is for testing with react-scripts (npm run start)
814
ReactDOM.render(
915
<React.StrictMode>
1016
<div className="theme-light">
1117
<div className="markdown-reading-view">
1218
<div className="markdown-preview-view">
13-
<App />
19+
<App data={data} />
1420
</div>
1521
</div>
1622
</div>

versions.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"0.0.0": "0.12.0",
2+
"0.1.0": "0.12.0",
33
"0.1.1": "0.12.0",
4-
"0.1.2": "0.12.0"
4+
"0.1.2": "0.12.0",
5+
"0.1.3": "0.12.0"
56
}

0 commit comments

Comments
 (0)