@signiphi/pdf-compose 0.1.0-beta.10 → 0.1.0-beta.11
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/components/ImageNodeView.d.ts +11 -0
- package/dist/components/ImageNodeView.d.ts.map +1 -0
- package/dist/extensions/image-node.d.ts +10 -0
- package/dist/extensions/image-node.d.ts.map +1 -0
- package/dist/hooks/useDocumentGenerator.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +85 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -7
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +25 -0
- package/dist/utils/markdown-parser.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NodeViewProps } from '@tiptap/react';
|
|
2
|
+
/**
|
|
3
|
+
* Editor view for an image node. When the node carries a directly renderable
|
|
4
|
+
* `src` (http(s) or data URL) we show the actual image so staff see exactly
|
|
5
|
+
* what the PDF will contain. When the image is deferred to a variable
|
|
6
|
+
* (`var:marinaLogoUrl` → empty `src` until generate time) we render a labeled
|
|
7
|
+
* dashed placeholder instead of a broken image. width/height are PDF points;
|
|
8
|
+
* we reuse them as px hints so the editor preview stays roughly proportional.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ImageNodeView({ node, selected }: NodeViewProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
//# sourceMappingURL=ImageNodeView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImageNodeView.d.ts","sourceRoot":"","sources":["../../src/components/ImageNodeView.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,aAAa,2CA8C9D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
/**
|
|
3
|
+
* Block-level image node. The markdown parser emits `imageNode` for both
|
|
4
|
+
* `{{image|...}}` tokens and standalone `` lines, and the writer +
|
|
5
|
+
* PDF generator both consume it — this extension registers the matching schema
|
|
6
|
+
* node so the editor can load and round-trip image content instead of
|
|
7
|
+
* rejecting the whole document as invalid.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ImageNode: Node<any, any>;
|
|
10
|
+
//# sourceMappingURL=image-node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-node.d.ts","sourceRoot":"","sources":["../../src/extensions/image-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,cAAc,CAAC;AAIrD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,gBA6BpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/hooks/useDocumentGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AASvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAa,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAgB,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"useDocumentGenerator.d.ts","sourceRoot":"","sources":["../../src/hooks/useDocumentGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AASvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAa,KAAK,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAgB,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CA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C5E,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,cAAc,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACxD,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,sBAAsB,CAAC,KAAK,IAAI,CAAC;IAClF,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;KAAE,CAAC,CAAC;IAClH,cAAc,EAAE,MAAM,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAAC;IACpE,cAAc,EAAE,MAAM,MAAM,CAAC;IAC7B,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,iBAAiB,CAAC;IAClD,YAAY,EAAE,CAAC,GAAG,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,0BAA0B,CA6T5B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { markdownToTiptap } from './utils/markdown-parser';
|
|
|
12
12
|
export { tiptapToMarkdown } from './utils/markdown-writer';
|
|
13
13
|
export { RepeatNode } from './extensions/repeat-node';
|
|
14
14
|
export { SubtotalsNode } from './extensions/subtotals-node';
|
|
15
|
+
export { ImageNode } from './extensions/image-node';
|
|
15
16
|
export { parseXmlTemplate } from './utils/xml-template-parser';
|
|
16
17
|
export type { XmlTemplateParseResult } from './utils/xml-template-parser';
|
|
17
18
|
export { ThemeProvider, useTheme } from './contexts/ThemeContext';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGpE,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,OAAO,GACR,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAGnJ,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC3F,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACvF,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE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@@ -452,6 +452,72 @@ var WatermarkNode = core.Node.create({
|
|
|
452
452
|
return react.ReactNodeViewRenderer(WatermarkNodeView);
|
|
453
453
|
}
|
|
454
454
|
});
|
|
455
|
+
function ImageNodeView({ node, selected }) {
|
|
456
|
+
const { src, varName, alt, width, height, align } = node.attrs;
|
|
457
|
+
const hasRenderableSrc = !!src && /^(https?:|data:)/i.test(src);
|
|
458
|
+
const wrapperJustify = align === "center" ? "justify-center" : align === "right" ? "justify-end" : "justify-start";
|
|
459
|
+
const toCssSize = (v) => /^\d+(\.\d+)?$/.test(v) ? `${v}px` : v;
|
|
460
|
+
const sizeStyle = {};
|
|
461
|
+
if (width) sizeStyle.width = toCssSize(width);
|
|
462
|
+
if (height) sizeStyle.height = toCssSize(height);
|
|
463
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.NodeViewWrapper, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("flex my-1", wrapperJustify), "data-image-node": "", children: hasRenderableSrc ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
464
|
+
"img",
|
|
465
|
+
{
|
|
466
|
+
src,
|
|
467
|
+
alt: alt || varName || "",
|
|
468
|
+
style: sizeStyle,
|
|
469
|
+
className: cn(
|
|
470
|
+
"max-w-full rounded-sm object-contain",
|
|
471
|
+
selected && "ring-2 ring-primary ring-offset-1"
|
|
472
|
+
),
|
|
473
|
+
draggable: false
|
|
474
|
+
}
|
|
475
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
476
|
+
"div",
|
|
477
|
+
{
|
|
478
|
+
"data-image-placeholder": "",
|
|
479
|
+
className: cn(
|
|
480
|
+
"inline-flex items-center gap-2 px-3 py-2 rounded-md border border-dashed text-sm",
|
|
481
|
+
"bg-slate-50 text-slate-500 border-slate-300",
|
|
482
|
+
selected && "ring-2 ring-primary ring-offset-1"
|
|
483
|
+
),
|
|
484
|
+
style: height ? { minHeight: toCssSize(height) } : void 0,
|
|
485
|
+
title: varName ? `Image variable: ${varName}` : "Image",
|
|
486
|
+
children: [
|
|
487
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Image, { size: 16 }),
|
|
488
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: varName ? `Image: ${varName}` : alt || "Image" })
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
) }) });
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/extensions/image-node.ts
|
|
495
|
+
var ImageNode = core.Node.create({
|
|
496
|
+
name: "imageNode",
|
|
497
|
+
group: "block",
|
|
498
|
+
atom: true,
|
|
499
|
+
selectable: true,
|
|
500
|
+
draggable: false,
|
|
501
|
+
addAttributes() {
|
|
502
|
+
return {
|
|
503
|
+
src: { default: "" },
|
|
504
|
+
varName: { default: "" },
|
|
505
|
+
alt: { default: "" },
|
|
506
|
+
width: { default: "" },
|
|
507
|
+
height: { default: "" },
|
|
508
|
+
align: { default: "" }
|
|
509
|
+
};
|
|
510
|
+
},
|
|
511
|
+
parseHTML() {
|
|
512
|
+
return [{ tag: "div[data-image-node]" }];
|
|
513
|
+
},
|
|
514
|
+
renderHTML({ HTMLAttributes }) {
|
|
515
|
+
return ["div", core.mergeAttributes({ "data-image-node": "" }, HTMLAttributes)];
|
|
516
|
+
},
|
|
517
|
+
addNodeView() {
|
|
518
|
+
return react.ReactNodeViewRenderer(ImageNodeView);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
455
521
|
var RepeatNode = core.Node.create({
|
|
456
522
|
name: "repeatBlock",
|
|
457
523
|
group: "block",
|
|
@@ -1096,11 +1162,23 @@ function parseBlocks(lines, startIdx, stopCondition) {
|
|
|
1096
1162
|
continue;
|
|
1097
1163
|
}
|
|
1098
1164
|
const inlineNodes = parseInline(line);
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1165
|
+
if (inlineNodes.some((n) => n.type === "imageNode")) {
|
|
1166
|
+
let run = [];
|
|
1167
|
+
const flushRun = () => {
|
|
1168
|
+
if (run.some((n) => !(n.type === "text" && !(n.text || "").trim()))) {
|
|
1169
|
+
content.push({ type: "paragraph", content: run });
|
|
1170
|
+
}
|
|
1171
|
+
run = [];
|
|
1172
|
+
};
|
|
1173
|
+
for (const n of inlineNodes) {
|
|
1174
|
+
if (n.type === "imageNode") {
|
|
1175
|
+
flushRun();
|
|
1176
|
+
content.push(n);
|
|
1177
|
+
} else {
|
|
1178
|
+
run.push(n);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
flushRun();
|
|
1104
1182
|
} else {
|
|
1105
1183
|
content.push({ type: "paragraph", content: inlineNodes });
|
|
1106
1184
|
}
|
|
@@ -3226,6 +3304,7 @@ function useDocumentGenerator(options = {}) {
|
|
|
3226
3304
|
ColumnsNode,
|
|
3227
3305
|
ColumnNode,
|
|
3228
3306
|
WatermarkNode,
|
|
3307
|
+
ImageNode,
|
|
3229
3308
|
RepeatNode,
|
|
3230
3309
|
SubtotalsNode
|
|
3231
3310
|
],
|
|
@@ -7465,6 +7544,7 @@ function parseXmlTemplate(xmlString) {
|
|
|
7465
7544
|
exports.DocumentGenerator = DocumentGenerator;
|
|
7466
7545
|
exports.EditorPanel = EditorPanel;
|
|
7467
7546
|
exports.FormFieldType = FormFieldType;
|
|
7547
|
+
exports.ImageNode = ImageNode;
|
|
7468
7548
|
exports.PreviewPanel = PreviewPanel;
|
|
7469
7549
|
exports.RepeatNode = RepeatNode;
|
|
7470
7550
|
exports.SubtotalsNode = SubtotalsNode;
|