react-ink-scripter 0.0.7 → 0.0.9
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/cjs/index.js +47 -14
- package/dist/esm/IFrame.d.ts +7 -0
- package/dist/esm/PrinterFrame.d.ts +7 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +38 -12
- package/package.json +4 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1,30 +1,62 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
3
|
var react = require('react');
|
|
5
4
|
var reactDom = require('react-dom');
|
|
6
|
-
var clsx = require('clsx');
|
|
7
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var clsx = require('clsx');
|
|
8
7
|
var _extends = require('@babel/runtime/helpers/extends');
|
|
9
8
|
|
|
9
|
+
var IFrame = react.forwardRef(function (props, ref) {
|
|
10
|
+
var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2;
|
|
11
|
+
var styleCss = props.styleCss,
|
|
12
|
+
className = props.className,
|
|
13
|
+
children = props.children;
|
|
14
|
+
var iframeRef = react.useRef(null);
|
|
15
|
+
var attachBody = iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : (_iframeRef$current$co = _iframeRef$current.contentWindow) === null || _iframeRef$current$co === void 0 ? void 0 : (_iframeRef$current$co2 = _iframeRef$current$co.document) === null || _iframeRef$current$co2 === void 0 ? void 0 : _iframeRef$current$co2.body;
|
|
16
|
+
var attachHead = iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.document) === null || _iframeRef$current2$c2 === void 0 ? void 0 : _iframeRef$current2$c2.head;
|
|
17
|
+
react.useImperativeHandle(ref, function () {
|
|
18
|
+
return iframeRef === null || iframeRef === void 0 ? void 0 : iframeRef.current;
|
|
19
|
+
}, []);
|
|
20
|
+
return jsxRuntime.jsxs("iframe", {
|
|
21
|
+
ref: iframeRef,
|
|
22
|
+
className: className,
|
|
23
|
+
children: [attachBody && reactDom.createPortal(children, attachBody), attachHead && reactDom.createPortal(jsxRuntime.jsx("style", {
|
|
24
|
+
children: styleCss
|
|
25
|
+
}), attachHead)]
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
10
29
|
var PrinterFrame = function PrinterFrame(props) {
|
|
11
|
-
var
|
|
30
|
+
var _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2, _iframeRef$current3, _iframeRef$current3$c, _iframeRef$current3$c2, _iframeRef$current4, _iframeRef$current4$c, _iframeRef$current4$c2;
|
|
12
31
|
var styleCss = props.styleCss,
|
|
13
32
|
open = props.open,
|
|
14
33
|
className = props.className,
|
|
15
|
-
children = props.children
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
34
|
+
children = props.children,
|
|
35
|
+
actionRef = props.actionRef,
|
|
36
|
+
src = props.src,
|
|
37
|
+
containerId = props.containerId;
|
|
38
|
+
var iframeRef = react.useRef(null);
|
|
39
|
+
react.useImperativeHandle(actionRef, function () {
|
|
40
|
+
return {
|
|
41
|
+
print: function print() {
|
|
42
|
+
var _iframeRef$current;
|
|
43
|
+
var cw = iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow;
|
|
44
|
+
if (cw) {
|
|
45
|
+
cw.focus();
|
|
46
|
+
cw.print();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}, []);
|
|
51
|
+
var attachNode = containerId ? iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current2 = iframeRef.current) === null || _iframeRef$current2 === void 0 ? void 0 : (_iframeRef$current2$c = _iframeRef$current2.contentWindow) === null || _iframeRef$current2$c === void 0 ? void 0 : (_iframeRef$current2$c2 = _iframeRef$current2$c.document) === null || _iframeRef$current2$c2 === void 0 ? void 0 : _iframeRef$current2$c2.getElementById(containerId) : iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current3 = iframeRef.current) === null || _iframeRef$current3 === void 0 ? void 0 : (_iframeRef$current3$c = _iframeRef$current3.contentWindow) === null || _iframeRef$current3$c === void 0 ? void 0 : (_iframeRef$current3$c2 = _iframeRef$current3$c.document) === null || _iframeRef$current3$c2 === void 0 ? void 0 : _iframeRef$current3$c2.body;
|
|
52
|
+
var attachStyle = iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current4 = iframeRef.current) === null || _iframeRef$current4 === void 0 ? void 0 : (_iframeRef$current4$c = _iframeRef$current4.contentWindow) === null || _iframeRef$current4$c === void 0 ? void 0 : (_iframeRef$current4$c2 = _iframeRef$current4$c.document) === null || _iframeRef$current4$c2 === void 0 ? void 0 : _iframeRef$current4$c2.head;
|
|
22
53
|
return jsxRuntime.jsxs("iframe", {
|
|
23
|
-
ref:
|
|
54
|
+
ref: iframeRef,
|
|
24
55
|
className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
56
|
+
src: src,
|
|
57
|
+
children: [!!attachStyle && reactDom.createPortal(jsxRuntime.jsxs("style", {
|
|
58
|
+
children: ["\n@media print {\n .hidden-print {\n display: none !important;\n }\n}\n ", styleCss]
|
|
59
|
+
}), attachStyle), !!attachNode && reactDom.createPortal(children, attachNode)]
|
|
28
60
|
});
|
|
29
61
|
};
|
|
30
62
|
|
|
@@ -227,5 +259,6 @@ var InkScripter = function InkScripter(props) {
|
|
|
227
259
|
});
|
|
228
260
|
};
|
|
229
261
|
|
|
262
|
+
exports.IFrame = IFrame;
|
|
230
263
|
exports.InkScripter = InkScripter;
|
|
231
264
|
exports.PrinterFrame = PrinterFrame;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export interface IFrameProps {
|
|
3
|
+
className?: string;
|
|
4
|
+
styleCss?: string;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const IFrame: import("react").ForwardRefExoticComponent<IFrameProps & import("react").RefAttributes<HTMLIFrameElement>>;
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
1
|
+
import { ReactNode, Ref } from "react";
|
|
2
|
+
export interface PrinterActions {
|
|
3
|
+
print: () => void;
|
|
4
|
+
}
|
|
2
5
|
export interface PrinterFrameProps {
|
|
3
6
|
styleCss?: string;
|
|
4
7
|
open?: boolean;
|
|
5
8
|
className?: string;
|
|
6
9
|
children?: ReactNode;
|
|
10
|
+
actionRef?: Ref<PrinterActions>;
|
|
11
|
+
src?: string;
|
|
12
|
+
containerId?: string;
|
|
7
13
|
}
|
|
8
14
|
export declare const PrinterFrame: (props: PrinterFrameProps) => JSX.Element;
|
|
9
15
|
export default PrinterFrame;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,19 +1,45 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { forwardRef, useRef, useImperativeHandle } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
|
|
6
|
+
const IFrame = forwardRef((props, ref) => {
|
|
7
|
+
const { styleCss, className, children } = props;
|
|
8
|
+
const iframeRef = useRef(null);
|
|
9
|
+
const attachBody = iframeRef?.current?.contentWindow?.document?.body;
|
|
10
|
+
const attachHead = iframeRef?.current?.contentWindow?.document?.head;
|
|
11
|
+
useImperativeHandle(ref, () => {
|
|
12
|
+
return iframeRef?.current;
|
|
13
|
+
}, []);
|
|
14
|
+
return (jsxs("iframe", { ref: iframeRef, className: className, children: [attachBody && createPortal(children, attachBody), attachHead && createPortal(jsx("style", { children: styleCss }), attachHead)] }));
|
|
15
|
+
});
|
|
16
|
+
|
|
6
17
|
const PrinterFrame = (props) => {
|
|
7
|
-
const { styleCss, open, className, children } = props;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
const { styleCss, open, className, children, actionRef, src, containerId } = props;
|
|
19
|
+
const iframeRef = useRef(null);
|
|
20
|
+
useImperativeHandle(actionRef, () => {
|
|
21
|
+
return {
|
|
22
|
+
print() {
|
|
23
|
+
const cw = iframeRef?.current?.contentWindow;
|
|
24
|
+
if (cw) {
|
|
25
|
+
cw.focus();
|
|
26
|
+
cw.print();
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
const attachNode = containerId
|
|
32
|
+
? iframeRef?.current?.contentWindow?.document?.getElementById(containerId)
|
|
33
|
+
: iframeRef?.current?.contentWindow?.document?.body;
|
|
34
|
+
const attachStyle = iframeRef?.current?.contentWindow?.document?.head;
|
|
35
|
+
return (jsxs("iframe", { ref: iframeRef, className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className), src: src, children: [!!attachStyle &&
|
|
36
|
+
createPortal(jsxs("style", { children: [`
|
|
37
|
+
@media print {
|
|
38
|
+
.hidden-print {
|
|
39
|
+
display: none !important;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`, styleCss] }), attachStyle), !!attachNode && createPortal(children, attachNode)] }));
|
|
17
43
|
};
|
|
18
44
|
|
|
19
45
|
const Title = ({ value, id }) => {
|
|
@@ -105,4 +131,4 @@ const InkScripter = (props) => {
|
|
|
105
131
|
}) }));
|
|
106
132
|
};
|
|
107
133
|
|
|
108
|
-
export { InkScripter, PrinterFrame };
|
|
134
|
+
export { IFrame, InkScripter, PrinterFrame };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-ink-scripter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "a react component for generate page to print",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"keywords": [
|
|
13
13
|
"react",
|
|
14
14
|
"component",
|
|
15
|
-
"
|
|
15
|
+
"print",
|
|
16
|
+
"printer",
|
|
17
|
+
"iframe"
|
|
16
18
|
],
|
|
17
19
|
"author": "lawrsp",
|
|
18
20
|
"license": "MIT",
|