react-ink-scripter 0.0.7 → 0.0.8
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 +43 -13
- package/dist/esm/IFrame.d.ts +7 -0
- package/dist/esm/PrinterFrame.d.ts +5 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +36 -12
- package/package.json +4 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1,29 +1,58 @@
|
|
|
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;
|
|
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
|
+
var iframeRef = react.useRef(null);
|
|
37
|
+
react.useImperativeHandle(actionRef, function () {
|
|
38
|
+
return {
|
|
39
|
+
print: function print() {
|
|
40
|
+
var _iframeRef$current;
|
|
41
|
+
var cw = iframeRef === null || iframeRef === void 0 ? void 0 : (_iframeRef$current = iframeRef.current) === null || _iframeRef$current === void 0 ? void 0 : _iframeRef$current.contentWindow;
|
|
42
|
+
if (cw) {
|
|
43
|
+
cw.focus();
|
|
44
|
+
cw.print();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
var attachBody = 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.body;
|
|
50
|
+
var attachHead = 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.head;
|
|
22
51
|
return jsxRuntime.jsxs("iframe", {
|
|
23
|
-
ref:
|
|
52
|
+
ref: iframeRef,
|
|
24
53
|
className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className),
|
|
25
|
-
children: [attachBody && reactDom.createPortal(children, attachBody), attachHead && reactDom.createPortal(jsxRuntime.jsxs("style", {
|
|
26
|
-
children: ["@media print {\n
|
|
54
|
+
children: [!!attachBody && reactDom.createPortal(children, attachBody), !!attachHead && reactDom.createPortal(jsxRuntime.jsxs("style", {
|
|
55
|
+
children: ["\n@media print {\n .hidden-print {\n display: none !important;\n }\n}\n ", styleCss]
|
|
27
56
|
}), attachHead)]
|
|
28
57
|
});
|
|
29
58
|
};
|
|
@@ -227,5 +256,6 @@ var InkScripter = function InkScripter(props) {
|
|
|
227
256
|
});
|
|
228
257
|
};
|
|
229
258
|
|
|
259
|
+
exports.IFrame = IFrame;
|
|
230
260
|
exports.InkScripter = InkScripter;
|
|
231
261
|
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,13 @@
|
|
|
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>;
|
|
7
11
|
}
|
|
8
12
|
export declare const PrinterFrame: (props: PrinterFrameProps) => JSX.Element;
|
|
9
13
|
export default PrinterFrame;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
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 } = 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 attachBody = iframeRef?.current?.contentWindow?.document?.body;
|
|
32
|
+
const attachHead = iframeRef?.current?.contentWindow?.document?.head;
|
|
33
|
+
return (jsxs("iframe", { ref: iframeRef, className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className), children: [!!attachBody && createPortal(children, attachBody), !!attachHead &&
|
|
34
|
+
createPortal(jsxs("style", { children: [`
|
|
35
|
+
@media print {
|
|
36
|
+
.hidden-print {
|
|
37
|
+
display: none !important;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`, styleCss] }), attachHead)] }));
|
|
17
41
|
};
|
|
18
42
|
|
|
19
43
|
const Title = ({ value, id }) => {
|
|
@@ -105,4 +129,4 @@ const InkScripter = (props) => {
|
|
|
105
129
|
}) }));
|
|
106
130
|
};
|
|
107
131
|
|
|
108
|
-
export { InkScripter, PrinterFrame };
|
|
132
|
+
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.8",
|
|
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",
|