react-ink-scripter 0.0.12 → 0.0.13
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 +25 -6
- package/dist/esm/IFrame.d.ts +4 -2
- package/dist/esm/InkScripter.d.ts +3 -3
- package/dist/esm/PrinterFrame.d.ts +4 -2
- package/dist/esm/index.js +16 -10
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
3
4
|
var react = require('react');
|
|
4
5
|
var reactDom = require('react-dom');
|
|
5
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -10,8 +11,16 @@ var IFrame = react.forwardRef(function (props, ref) {
|
|
|
10
11
|
var _iframeRef$current, _iframeRef$current$co, _iframeRef$current$co2, _iframeRef$current2, _iframeRef$current2$c, _iframeRef$current2$c2;
|
|
11
12
|
var styleCss = props.styleCss,
|
|
12
13
|
className = props.className,
|
|
13
|
-
children = props.children
|
|
14
|
+
children = props.children,
|
|
15
|
+
width = props.width,
|
|
16
|
+
height = props.height;
|
|
14
17
|
var iframeRef = react.useRef(null);
|
|
18
|
+
var _useMemo = react.useMemo(function () {
|
|
19
|
+
return [width, height];
|
|
20
|
+
}, [width, height]),
|
|
21
|
+
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
22
|
+
frameWidth = _useMemo2[0],
|
|
23
|
+
frameHeight = _useMemo2[1];
|
|
15
24
|
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
25
|
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
26
|
react.useImperativeHandle(ref, function () {
|
|
@@ -20,13 +29,15 @@ var IFrame = react.forwardRef(function (props, ref) {
|
|
|
20
29
|
return jsxRuntime.jsxs("iframe", {
|
|
21
30
|
ref: iframeRef,
|
|
22
31
|
className: className,
|
|
32
|
+
width: frameWidth,
|
|
33
|
+
height: frameHeight,
|
|
23
34
|
children: [attachBody && reactDom.createPortal(children, attachBody), attachHead && reactDom.createPortal(jsxRuntime.jsx("style", {
|
|
24
35
|
children: styleCss
|
|
25
36
|
}), attachHead)]
|
|
26
37
|
});
|
|
27
38
|
});
|
|
28
39
|
|
|
29
|
-
var PrinterFrame = function
|
|
40
|
+
var PrinterFrame = react.forwardRef(function (props, ref) {
|
|
30
41
|
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;
|
|
31
42
|
var styleCss = props.styleCss,
|
|
32
43
|
open = props.open,
|
|
@@ -34,7 +45,9 @@ var PrinterFrame = function PrinterFrame(props) {
|
|
|
34
45
|
children = props.children,
|
|
35
46
|
actionRef = props.actionRef,
|
|
36
47
|
src = props.src,
|
|
37
|
-
containerId = props.containerId
|
|
48
|
+
containerId = props.containerId,
|
|
49
|
+
width = props.width,
|
|
50
|
+
height = props.height;
|
|
38
51
|
var iframeRef = react.useRef(null);
|
|
39
52
|
react.useImperativeHandle(actionRef, function () {
|
|
40
53
|
return {
|
|
@@ -48,17 +61,22 @@ var PrinterFrame = function PrinterFrame(props) {
|
|
|
48
61
|
}
|
|
49
62
|
};
|
|
50
63
|
}, []);
|
|
64
|
+
react.useImperativeHandle(ref, function () {
|
|
65
|
+
return iframeRef === null || iframeRef === void 0 ? void 0 : iframeRef.current;
|
|
66
|
+
});
|
|
51
67
|
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
68
|
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;
|
|
53
69
|
return jsxRuntime.jsxs("iframe", {
|
|
54
70
|
ref: iframeRef,
|
|
55
71
|
className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className),
|
|
56
72
|
src: src,
|
|
73
|
+
width: width,
|
|
74
|
+
height: height,
|
|
57
75
|
children: [!!attachStyle && reactDom.createPortal(jsxRuntime.jsxs("style", {
|
|
58
76
|
children: ["\n@media print {\n .hidden-print {\n display: none !important;\n }\n}\n ", styleCss]
|
|
59
77
|
}), attachStyle), !!attachNode && reactDom.createPortal(children, attachNode)]
|
|
60
78
|
});
|
|
61
|
-
};
|
|
79
|
+
});
|
|
62
80
|
|
|
63
81
|
var Container = function Container(_ref) {
|
|
64
82
|
var id = _ref.id,
|
|
@@ -220,12 +238,13 @@ var Pair = function Pair(_ref5) {
|
|
|
220
238
|
})]
|
|
221
239
|
});
|
|
222
240
|
};
|
|
223
|
-
var InkScripter = function
|
|
241
|
+
var InkScripter = react.forwardRef(function (props, ref) {
|
|
224
242
|
var _props$value = props.value,
|
|
225
243
|
value = _props$value === void 0 ? [] : _props$value,
|
|
226
244
|
className = props.className;
|
|
227
245
|
return jsxRuntime.jsx("div", {
|
|
228
246
|
className: clsx("inks-root", className),
|
|
247
|
+
ref: ref,
|
|
229
248
|
children: value.map(function (item, index) {
|
|
230
249
|
switch (item.type) {
|
|
231
250
|
case "grid":
|
|
@@ -239,7 +258,7 @@ var InkScripter = function InkScripter(props) {
|
|
|
239
258
|
}
|
|
240
259
|
})
|
|
241
260
|
});
|
|
242
|
-
};
|
|
261
|
+
});
|
|
243
262
|
|
|
244
263
|
exports.IFrame = IFrame;
|
|
245
264
|
exports.InkScripter = InkScripter;
|
package/dist/esm/IFrame.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
1
|
+
import type { ReactNode, ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
2
|
export interface IFrameProps {
|
|
3
3
|
className?: string;
|
|
4
4
|
styleCss?: string;
|
|
5
5
|
children?: ReactNode;
|
|
6
|
+
width?: string | number;
|
|
7
|
+
height?: string | number;
|
|
6
8
|
}
|
|
7
|
-
export declare const IFrame:
|
|
9
|
+
export declare const IFrame: ForwardRefExoticComponent<IFrameProps & RefAttributes<any>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
2
|
export type ContentTextItem = {
|
|
3
3
|
id?: string;
|
|
4
4
|
className?: string;
|
|
@@ -36,9 +36,9 @@ export type ContentTableItem = {
|
|
|
36
36
|
};
|
|
37
37
|
export type ContentItemType = ContentGridItem | ContentTableItem | ContentTextItem | ContentPairItem;
|
|
38
38
|
export type ContentType = ContentItemType[];
|
|
39
|
-
export type
|
|
39
|
+
export type InkScripterProps = {
|
|
40
40
|
value?: ContentType;
|
|
41
41
|
className?: string;
|
|
42
42
|
};
|
|
43
|
-
export declare const InkScripter:
|
|
43
|
+
export declare const InkScripter: ForwardRefExoticComponent<InkScripterProps & RefAttributes<any>>;
|
|
44
44
|
export default InkScripter;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode,
|
|
1
|
+
import type { Ref, ReactNode, ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
2
|
export interface PrinterActions {
|
|
3
3
|
print: () => void;
|
|
4
4
|
}
|
|
@@ -10,6 +10,8 @@ export interface PrinterFrameProps {
|
|
|
10
10
|
actionRef?: Ref<PrinterActions>;
|
|
11
11
|
src?: string;
|
|
12
12
|
containerId?: string;
|
|
13
|
+
width?: string | number;
|
|
14
|
+
height?: string | number;
|
|
13
15
|
}
|
|
14
|
-
export declare const PrinterFrame:
|
|
16
|
+
export declare const PrinterFrame: ForwardRefExoticComponent<PrinterFrameProps & RefAttributes<any>>;
|
|
15
17
|
export default PrinterFrame;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { forwardRef, useRef, useImperativeHandle } from 'react';
|
|
2
|
+
import { forwardRef, useRef, useMemo, useImperativeHandle } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
|
|
6
6
|
const IFrame = forwardRef((props, ref) => {
|
|
7
|
-
const { styleCss, className, children } = props;
|
|
7
|
+
const { styleCss, className, children, width, height } = props;
|
|
8
8
|
const iframeRef = useRef(null);
|
|
9
|
+
const [frameWidth, frameHeight] = useMemo(() => {
|
|
10
|
+
return [width, height];
|
|
11
|
+
}, [width, height]);
|
|
9
12
|
const attachBody = iframeRef?.current?.contentWindow?.document?.body;
|
|
10
13
|
const attachHead = iframeRef?.current?.contentWindow?.document?.head;
|
|
11
14
|
useImperativeHandle(ref, () => {
|
|
12
15
|
return iframeRef?.current;
|
|
13
16
|
}, []);
|
|
14
|
-
return (jsxs("iframe", { ref: iframeRef, className: className, children: [attachBody && createPortal(children, attachBody), attachHead && createPortal(jsx("style", { children: styleCss }), attachHead)] }));
|
|
17
|
+
return (jsxs("iframe", { ref: iframeRef, className: className, width: frameWidth, height: frameHeight, children: [attachBody && createPortal(children, attachBody), attachHead && createPortal(jsx("style", { children: styleCss }), attachHead)] }));
|
|
15
18
|
});
|
|
16
19
|
|
|
17
|
-
const PrinterFrame = (props) => {
|
|
18
|
-
const { styleCss, open, className, children, actionRef, src, containerId } = props;
|
|
20
|
+
const PrinterFrame = forwardRef((props, ref) => {
|
|
21
|
+
const { styleCss, open, className, children, actionRef, src, containerId, width, height, } = props;
|
|
19
22
|
const iframeRef = useRef(null);
|
|
20
23
|
useImperativeHandle(actionRef, () => {
|
|
21
24
|
return {
|
|
@@ -28,11 +31,14 @@ const PrinterFrame = (props) => {
|
|
|
28
31
|
},
|
|
29
32
|
};
|
|
30
33
|
}, []);
|
|
34
|
+
useImperativeHandle(ref, () => {
|
|
35
|
+
return iframeRef?.current;
|
|
36
|
+
});
|
|
31
37
|
const attachNode = containerId
|
|
32
38
|
? iframeRef?.current?.contentWindow?.document?.getElementById(containerId)
|
|
33
39
|
: iframeRef?.current?.contentWindow?.document?.body;
|
|
34
40
|
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 &&
|
|
41
|
+
return (jsxs("iframe", { ref: iframeRef, className: clsx("inks-iframe-root", !!open && "inks-iframe-root-open", className), src: src, width: width, height: height, children: [!!attachStyle &&
|
|
36
42
|
createPortal(jsxs("style", { children: [`
|
|
37
43
|
@media print {
|
|
38
44
|
.hidden-print {
|
|
@@ -40,7 +46,7 @@ const PrinterFrame = (props) => {
|
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
`, styleCss] }), attachStyle), !!attachNode && createPortal(children, attachNode)] }));
|
|
43
|
-
};
|
|
49
|
+
});
|
|
44
50
|
|
|
45
51
|
const Container = ({ id, content = [], className, }) => {
|
|
46
52
|
return (jsx("div", { id: id, className: clsx("inks-grid", className), children: content.map((item, idx) => {
|
|
@@ -105,9 +111,9 @@ const Text = ({ id, value, span, className }) => {
|
|
|
105
111
|
const Pair = ({ id, value, label, span, className }) => {
|
|
106
112
|
return (jsxs("div", { id: id, className: clsx("inks-pair", span && "inks-grid", span && `inks-span-${span}`, className), children: [jsxs("label", { className: "inks-pair-label", children: [label, ":"] }), jsx("div", { className: "inks-pair-value", children: value })] }));
|
|
107
113
|
};
|
|
108
|
-
const InkScripter = (props) => {
|
|
114
|
+
const InkScripter = forwardRef((props, ref) => {
|
|
109
115
|
const { value = [], className } = props;
|
|
110
|
-
return (jsx("div", { className: clsx("inks-root", className), children: value.map((item, index) => {
|
|
116
|
+
return (jsx("div", { className: clsx("inks-root", className), ref: ref, children: value.map((item, index) => {
|
|
111
117
|
switch (item.type) {
|
|
112
118
|
case "grid":
|
|
113
119
|
return jsx(Grid, { ...item }, index);
|
|
@@ -119,6 +125,6 @@ const InkScripter = (props) => {
|
|
|
119
125
|
return jsx(Pair, { ...item }, index);
|
|
120
126
|
}
|
|
121
127
|
}) }));
|
|
122
|
-
};
|
|
128
|
+
});
|
|
123
129
|
|
|
124
130
|
export { IFrame, InkScripter, PrinterFrame };
|