@edv4h/usketch-plugin-shape-markdown 0.1.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.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/external-content-handler.d.ts +17 -0
- package/dist/external-content-handler.d.ts.map +1 -0
- package/dist/external-content-handler.js +93 -0
- package/dist/external-content-handler.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-editing-machine.d.ts +39 -0
- package/dist/markdown-editing-machine.d.ts.map +1 -0
- package/dist/markdown-editing-machine.js +190 -0
- package/dist/markdown-editing-machine.js.map +1 -0
- package/dist/plugin.d.ts +3 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +223 -0
- package/dist/plugin.js.map +1 -0
- package/dist/render.d.ts +11 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +280 -0
- package/dist/render.js.map +1 -0
- package/dist/selection-store.d.ts +7 -0
- package/dist/selection-store.d.ts.map +1 -0
- package/dist/selection-store.js +37 -0
- package/dist/selection-store.js.map +1 -0
- package/dist/table-paste.d.ts +23 -0
- package/dist/table-paste.d.ts.map +1 -0
- package/dist/table-paste.js +72 -0
- package/dist/table-paste.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers to detect tabular clipboard content (HTML `<table>` from
|
|
3
|
+
* Excel/Google Sheets/web, or delimited TSV/CSV text) and turn it into a GFM
|
|
4
|
+
* markdown table string. Used by the table external-content handler so a paste
|
|
5
|
+
* of a spreadsheet selection becomes a rendered markdown table shape.
|
|
6
|
+
*/
|
|
7
|
+
/** Cheap check for `match`: does the HTML payload contain a table element? */
|
|
8
|
+
export function htmlHasTable(html) {
|
|
9
|
+
return !!html && /<table[\s>]/i.test(html);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse an HTML `<table>` (e.g. Excel / Google Sheets rich clipboard) into a
|
|
13
|
+
* grid of cell strings. Browser-only (uses DOMParser); returns null otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export function parseHtmlTable(html) {
|
|
16
|
+
if (!html || typeof DOMParser === "undefined")
|
|
17
|
+
return null;
|
|
18
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
19
|
+
const table = doc.querySelector("table");
|
|
20
|
+
if (!table)
|
|
21
|
+
return null;
|
|
22
|
+
const rows = [];
|
|
23
|
+
for (const tr of Array.from(table.querySelectorAll("tr"))) {
|
|
24
|
+
const cells = Array.from(tr.querySelectorAll("th,td")).map((c) => (c.textContent ?? "").trim().replace(/\s+/g, " "));
|
|
25
|
+
if (cells.length > 0)
|
|
26
|
+
rows.push(cells);
|
|
27
|
+
}
|
|
28
|
+
return rows.length > 0 ? rows : null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse delimited plain text (TSV preferred, else CSV) into a grid. Conservative
|
|
32
|
+
* to avoid turning prose into a table: requires ≥2 non-empty lines, ≥2 columns,
|
|
33
|
+
* the delimiter present on *every* line, and a consistent column count.
|
|
34
|
+
* (No CSV quote handling — a pragmatic v1 for spreadsheet copies.)
|
|
35
|
+
*/
|
|
36
|
+
export function parseDelimited(text) {
|
|
37
|
+
if (!text)
|
|
38
|
+
return null;
|
|
39
|
+
const lines = text.replace(/\r\n?/g, "\n").split("\n");
|
|
40
|
+
while (lines.length > 0 && lines[lines.length - 1] === "")
|
|
41
|
+
lines.pop();
|
|
42
|
+
if (lines.length < 2)
|
|
43
|
+
return null;
|
|
44
|
+
if (lines.some((l) => l.trim() === ""))
|
|
45
|
+
return null;
|
|
46
|
+
const delim = lines.every((l) => l.includes("\t"))
|
|
47
|
+
? "\t"
|
|
48
|
+
: lines.every((l) => l.includes(","))
|
|
49
|
+
? ","
|
|
50
|
+
: null;
|
|
51
|
+
if (!delim)
|
|
52
|
+
return null;
|
|
53
|
+
const rows = lines.map((l) => l.split(delim).map((c) => c.trim()));
|
|
54
|
+
const cols = rows[0].length;
|
|
55
|
+
if (cols < 2)
|
|
56
|
+
return null;
|
|
57
|
+
if (!rows.every((r) => r.length === cols))
|
|
58
|
+
return null;
|
|
59
|
+
return rows;
|
|
60
|
+
}
|
|
61
|
+
/** Render a grid as a GFM table. First row is the header. */
|
|
62
|
+
export function toMarkdownTable(rows) {
|
|
63
|
+
const cols = Math.max(...rows.map((r) => r.length));
|
|
64
|
+
const escapeCell = (s) => s.replace(/\|/g, "\\|").replace(/\n/g, " ");
|
|
65
|
+
const pad = (r) => Array.from({ length: cols }, (_, i) => escapeCell(r[i] ?? ""));
|
|
66
|
+
const line = (cells) => `| ${cells.join(" | ")} |`;
|
|
67
|
+
const header = pad(rows[0]);
|
|
68
|
+
const sep = header.map(() => "---");
|
|
69
|
+
const body = rows.slice(1).map(pad);
|
|
70
|
+
return [line(header), line(sep), ...body.map(line)].join("\n");
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=table-paste.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-paste.js","sourceRoot":"","sources":["../src/table-paste.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,8EAA8E;AAC9E,MAAM,UAAU,YAAY,CAAC,IAA+B;IAC3D,OAAO,CAAC,CAAC,IAAI,IAAI,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAA+B;IAC7D,IAAI,CAAC,IAAI,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAC3D,MAA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AAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC9E,MAAM,GAAG,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5F,MAAM,IAAI,GAAG,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IAC7D,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ShapeData } from "@edv4h/usketch-shared";
|
|
2
|
+
/** Shape type id for the markdown shape. */
|
|
3
|
+
export declare const MARKDOWN_TYPE = "markdown";
|
|
4
|
+
/**
|
|
5
|
+
* Markdown shape metadata. Shape-specific data lives under `meta` (per the
|
|
6
|
+
* project convention: prefer `ShapeData<TMeta>` over `extends ShapeData`).
|
|
7
|
+
*
|
|
8
|
+
* - `source` — raw Markdown source (edited directly, rendered to GFM on view).
|
|
9
|
+
* - `isEditing` — transient edit-mode flag the renderer switches on.
|
|
10
|
+
*/
|
|
11
|
+
export interface MarkdownMeta {
|
|
12
|
+
source: string;
|
|
13
|
+
isEditing: boolean;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export type MarkdownShapeData = ShapeData<MarkdownMeta>;
|
|
17
|
+
/** Read `meta` with safe defaults (meta is optional / loosely typed on ShapeData). */
|
|
18
|
+
export declare function readMarkdownMeta(shape: ShapeData): MarkdownMeta;
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,4CAA4C;AAC5C,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,OAAO,CAAC;IAGnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAExD,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,GAAG,YAAY,CAM/D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Shape type id for the markdown shape. */
|
|
2
|
+
export const MARKDOWN_TYPE = "markdown";
|
|
3
|
+
/** Read `meta` with safe defaults (meta is optional / loosely typed on ShapeData). */
|
|
4
|
+
export function readMarkdownMeta(shape) {
|
|
5
|
+
const meta = shape.meta;
|
|
6
|
+
return {
|
|
7
|
+
source: typeof meta?.source === "string" ? meta.source : "",
|
|
8
|
+
isEditing: meta?.isEditing === true,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AAmBxC,sFAAsF;AACtF,MAAM,UAAU,gBAAgB,CAAC,KAAgB;IAChD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAyC,CAAC;IAC7D,OAAO;QACN,MAAM,EAAE,OAAO,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QAC3D,SAAS,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI;KACnC,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edv4h/usketch-plugin-shape-markdown",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@zag-js/core": "^1.37.0",
|
|
16
|
+
"@zag-js/vanilla": "^1.37.0",
|
|
17
|
+
"mermaid": "^11.4.0",
|
|
18
|
+
"react-markdown": "^9.0.1",
|
|
19
|
+
"rehype-highlight": "^7.0.1",
|
|
20
|
+
"remark-gfm": "^4.0.0",
|
|
21
|
+
"@edv4h/usketch-shared": "4.5.0",
|
|
22
|
+
"@edv4h/usketch-store": "3.3.1"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"react": ">=19"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/react": "19.2.17",
|
|
29
|
+
"typescript": "7.0.2",
|
|
30
|
+
"vitest": "4.1.10"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/EdV4H/usketch.git",
|
|
43
|
+
"directory": "plugins/usketch-plugin-shape-markdown"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/EdV4H/usketch#readme",
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/EdV4H/usketch/issues"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc -p tsconfig.json",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "vitest run --passWithNoTests",
|
|
53
|
+
"clean": "rm -rf dist"
|
|
54
|
+
}
|
|
55
|
+
}
|