@d1vij/jassm 0.1.14 → 0.1.15
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/dist/index.d.ts +6 -4
- package/dist/index.js +147 -8
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { MDXComponents } from "mdx/types";
|
|
|
2
2
|
type MDXComponent = MDXComponents[number];
|
|
3
3
|
declare const BaseElementTags: readonly ["h1", "h2", "h3", "h4", "h5", "h6", "a", "em", "del", "strong", "code", "blockquote", "pre", "p", "hr", "ol", "ul", "li", "img", "table", "thead", "tbody", "th", "tr", "td"];
|
|
4
4
|
declare const BaseElements: Record<(typeof BaseElementTags)[number], MDXComponent>;
|
|
5
|
+
import { ComponentPropsWithoutRef, ElementType } from "react";
|
|
6
|
+
type ElementProps<T extends ElementType> = ComponentPropsWithoutRef<T>;
|
|
5
7
|
type JSX = React.JSX.Element | null;
|
|
6
8
|
type HeaderLevels = 1 | 2 | 3 | 4 | 5 | 6;
|
|
7
9
|
import { MDXComponents as MDXComponents2, MDXProps } from "mdx/types";
|
|
@@ -145,13 +147,13 @@ declare class CoalescedRegistry<R extends readonly AbstractRegistry<Record<strin
|
|
|
145
147
|
/**
|
|
146
148
|
* List of default style classes
|
|
147
149
|
*/
|
|
148
|
-
declare const StyleClassesList: readonly ["header", "header_button", "header_1", "header_2", "header_3", "header_4", "header_5", "header_6", "header_icon", "anchor", "button", "bold", "italic", "span", "striked", "paragraph", "code", "preformatted", "blockquote", "horizontal_line", "image", "list", "unordered_list", "ordered_list", "list_item", "table", "table_head", "table_head_cell", "table_body", "table_row", "table_data"];
|
|
150
|
+
declare const StyleClassesList: readonly ["header", "header_button", "header_1", "header_2", "header_3", "header_4", "header_5", "header_6", "header_icon", "anchor", "button", "bold", "italic", "span", "striked", "paragraph", "code", "preformatted", "blockquote", "horizontal_line", "image", "list", "unordered_list", "ordered_list", "list_item", "table", "table_head", "table_head_cell", "table_body", "table_row", "table_data", "table_container", "table_action_buttons_details", "table_action_buttons_summary", "table_action_button", "table_action_button_html", "table_action_button_csv", "table_action_button_json", "table_action_button_markdown"];
|
|
149
151
|
type StyleClasses = (typeof StyleClassesList)[number];
|
|
150
|
-
type StyleClassesMap =
|
|
152
|
+
type StyleClassesMap = { [K in StyleClasses] : string };
|
|
151
153
|
/**
|
|
152
154
|
* Context which defines styles for the loaded component(s)
|
|
153
155
|
*/
|
|
154
|
-
declare const StyleContext: React.Context<StyleClassesMap>;
|
|
156
|
+
declare const StyleContext: React.Context<StyleClassesMap | null>;
|
|
155
157
|
/**
|
|
156
158
|
* Hook to get defined style classes map
|
|
157
159
|
* @returns {@link StyleClassesMap}
|
|
@@ -167,4 +169,4 @@ type MDXFromComponentProps = {
|
|
|
167
169
|
* Simple way to directly load a component from the Registry
|
|
168
170
|
*/
|
|
169
171
|
declare function MDXFromComponent({ source: SourceComponent, styles, fallback, elements }: MDXFromComponentProps): JSX;
|
|
170
|
-
export { useStyles, generateRegistries, generateElementsFrom, StyleContext, StyleClassesMap, StyleClassesList, StyleClasses, RegistryOptions, RegistryOf, RegistryKey, Registry, MDXFromComponentProps, MDXFromComponent, MDXFile, MDXComponent, HeaderLevels, ExportsRegistry, ExportSingleType, ExportAllType, Element2 as Element, ComponentRegistry, CoalescedRegistry, BaseElements, BaseElementTags };
|
|
172
|
+
export { useStyles, generateRegistries, generateElementsFrom, StyleContext, StyleClassesMap, StyleClassesList, StyleClasses, RegistryOptions, RegistryOf, RegistryKey, Registry, MDXFromComponentProps, MDXFromComponent, MDXFile, MDXComponent, HeaderLevels, ExportsRegistry, ExportSingleType, ExportAllType, ElementProps, Element2 as Element, ComponentRegistry, CoalescedRegistry, BaseElements, BaseElementTags };
|
package/dist/index.js
CHANGED
|
@@ -35,11 +35,22 @@ var StyleClassesList = [
|
|
|
35
35
|
"table_head_cell",
|
|
36
36
|
"table_body",
|
|
37
37
|
"table_row",
|
|
38
|
-
"table_data"
|
|
38
|
+
"table_data",
|
|
39
|
+
"table_container",
|
|
40
|
+
"table_action_buttons_details",
|
|
41
|
+
"table_action_buttons_summary",
|
|
42
|
+
"table_action_button",
|
|
43
|
+
"table_action_button_html",
|
|
44
|
+
"table_action_button_csv",
|
|
45
|
+
"table_action_button_json",
|
|
46
|
+
"table_action_button_markdown"
|
|
39
47
|
];
|
|
40
|
-
var StyleContext = createContext(
|
|
48
|
+
var StyleContext = createContext(null);
|
|
41
49
|
function useStyles() {
|
|
42
|
-
|
|
50
|
+
const ctx = useContext(StyleContext);
|
|
51
|
+
if (ctx === null)
|
|
52
|
+
throw new Error("No stylesmap found at any parent level. Either you forgot to pass the stylesmap to component loader or didnt wrap your component in StyleContext");
|
|
53
|
+
return ctx;
|
|
43
54
|
}
|
|
44
55
|
|
|
45
56
|
// src/components/Elements/Anchor.tsx
|
|
@@ -218,13 +229,141 @@ function Striked(props) {
|
|
|
218
229
|
}
|
|
219
230
|
|
|
220
231
|
// src/components/Elements/Table.tsx
|
|
221
|
-
import { cn as cn13 } from "@d1vij/shit-i-always-use";
|
|
222
|
-
import {
|
|
232
|
+
import { cn as cn13, useClipboardText as useClipboardText2 } from "@d1vij/shit-i-always-use";
|
|
233
|
+
import { useRef as useRef2 } from "react";
|
|
234
|
+
import { jsx as jsx13, jsxs } from "react/jsx-runtime";
|
|
235
|
+
function TableActionButton({ label, onClick }) {
|
|
236
|
+
const styles = useStyles();
|
|
237
|
+
return /* @__PURE__ */ jsx13("button", {
|
|
238
|
+
onClick,
|
|
239
|
+
className: cn13(styles.table_action_button),
|
|
240
|
+
type: "button",
|
|
241
|
+
children: label
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function getTableAsJson(elm) {
|
|
245
|
+
const headings = [];
|
|
246
|
+
const theadElms = elm.querySelectorAll("thead > tr > th");
|
|
247
|
+
theadElms.forEach((th) => {
|
|
248
|
+
headings.push(th.innerText.trim());
|
|
249
|
+
});
|
|
250
|
+
const rows = [];
|
|
251
|
+
const rowElms = elm.querySelectorAll("tbody > tr");
|
|
252
|
+
rowElms.forEach((tr) => {
|
|
253
|
+
const row = [];
|
|
254
|
+
tr.querySelectorAll("td").forEach((td, idx) => {
|
|
255
|
+
row.push({
|
|
256
|
+
column: headings[idx] ?? idx.toString(),
|
|
257
|
+
content: td.innerText.trim()
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
rows.push(row);
|
|
261
|
+
});
|
|
262
|
+
return {
|
|
263
|
+
meta: {
|
|
264
|
+
columns: headings.length,
|
|
265
|
+
rows: rowElms.length
|
|
266
|
+
},
|
|
267
|
+
headings,
|
|
268
|
+
rows
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function getTableJsonAsCsv(json) {
|
|
272
|
+
const heading = json.headings.join(",");
|
|
273
|
+
const rows = json.rows.map((row) => row.map((cell) => cell.content).join(",")).join(`
|
|
274
|
+
`);
|
|
275
|
+
return [heading, rows].join(`
|
|
276
|
+
`);
|
|
277
|
+
}
|
|
278
|
+
function getTableJsonAsHtml(json) {
|
|
279
|
+
const heading = json.headings.map((h) => `<th>${h}</th>`).join("");
|
|
280
|
+
const rows = json.rows.map((row) => {
|
|
281
|
+
const cells = row.map((c) => `<td>${c.content}</td>`).join("");
|
|
282
|
+
return `<tr>${cells}</tr>`;
|
|
283
|
+
});
|
|
284
|
+
return [
|
|
285
|
+
"<table>",
|
|
286
|
+
"<thead>",
|
|
287
|
+
`<tr>${heading}</tr>`,
|
|
288
|
+
"</thead>",
|
|
289
|
+
"<tbody>",
|
|
290
|
+
...rows,
|
|
291
|
+
"</tbody>",
|
|
292
|
+
"</table>"
|
|
293
|
+
].join(`
|
|
294
|
+
`);
|
|
295
|
+
}
|
|
296
|
+
function getTableJsonAsMarkdown(json) {
|
|
297
|
+
const heading = `|${json.headings.join("|")}|`;
|
|
298
|
+
const separator = `|${json.headings.map(() => "-----").join("|")}|`;
|
|
299
|
+
const rows = json.rows.map((row) => `|${row.map((cell) => cell.content).join("|")}|`);
|
|
300
|
+
return [heading, separator, ...rows].join(`
|
|
301
|
+
`);
|
|
302
|
+
}
|
|
223
303
|
function Table(props) {
|
|
224
304
|
const styles = useStyles();
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
305
|
+
const ref = useRef2(null);
|
|
306
|
+
const { copy } = useClipboardText2();
|
|
307
|
+
function copyAs(_as) {
|
|
308
|
+
return async () => {
|
|
309
|
+
const elm = ref.current;
|
|
310
|
+
if (!elm)
|
|
311
|
+
return;
|
|
312
|
+
const json = getTableAsJson(elm);
|
|
313
|
+
let extractedText;
|
|
314
|
+
switch (_as) {
|
|
315
|
+
case "html":
|
|
316
|
+
extractedText = getTableJsonAsHtml(json);
|
|
317
|
+
break;
|
|
318
|
+
case "csv":
|
|
319
|
+
extractedText = getTableJsonAsCsv(json);
|
|
320
|
+
break;
|
|
321
|
+
case "markdown":
|
|
322
|
+
extractedText = getTableJsonAsMarkdown(json);
|
|
323
|
+
break;
|
|
324
|
+
case "json":
|
|
325
|
+
extractedText = JSON.stringify(json, null, 4);
|
|
326
|
+
break;
|
|
327
|
+
default:
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
await copy(extractedText);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
334
|
+
className: cn13(styles.table_container),
|
|
335
|
+
children: [
|
|
336
|
+
/* @__PURE__ */ jsx13("table", {
|
|
337
|
+
ref,
|
|
338
|
+
className: cn13(styles.table),
|
|
339
|
+
children: props.children
|
|
340
|
+
}),
|
|
341
|
+
/* @__PURE__ */ jsxs("details", {
|
|
342
|
+
className: cn13(styles.table_action_buttons_details),
|
|
343
|
+
children: [
|
|
344
|
+
/* @__PURE__ */ jsx13("summary", {
|
|
345
|
+
className: cn13(styles.table_action_buttons_summary),
|
|
346
|
+
children: "Copy"
|
|
347
|
+
}),
|
|
348
|
+
/* @__PURE__ */ jsx13(TableActionButton, {
|
|
349
|
+
label: "HTML",
|
|
350
|
+
onClick: copyAs("html")
|
|
351
|
+
}),
|
|
352
|
+
/* @__PURE__ */ jsx13(TableActionButton, {
|
|
353
|
+
label: "CSV",
|
|
354
|
+
onClick: copyAs("csv")
|
|
355
|
+
}),
|
|
356
|
+
/* @__PURE__ */ jsx13(TableActionButton, {
|
|
357
|
+
label: "Json",
|
|
358
|
+
onClick: copyAs("json")
|
|
359
|
+
}),
|
|
360
|
+
/* @__PURE__ */ jsx13(TableActionButton, {
|
|
361
|
+
label: "Markdown",
|
|
362
|
+
onClick: copyAs("markdown")
|
|
363
|
+
})
|
|
364
|
+
]
|
|
365
|
+
})
|
|
366
|
+
]
|
|
228
367
|
});
|
|
229
368
|
}
|
|
230
369
|
function TableHead(props) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d1vij/jassm",
|
|
3
3
|
"description": "Just another static site maker. Create simple content driven sites using MDX and React along with Typescript safety.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"type-check": "tsc --noEmit",
|
|
39
39
|
"prepack": "bun run build",
|
|
40
40
|
"release": "bumpp --commit --push --tag",
|
|
41
|
-
"lint": "biome check --fix && tsc -b",
|
|
41
|
+
"lint": "biome check --fix --unsafe && tsc -b",
|
|
42
42
|
"format": "biome format --write"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|