react-ink-scripter 0.0.11 → 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 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 PrinterFrame(props) {
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,
@@ -71,13 +89,13 @@ var Container = function Container(_ref) {
71
89
  children: content.map(function (item, idx) {
72
90
  switch (item.type) {
73
91
  case "pair":
74
- return jsxRuntime.jsx(Pair, _extends({
75
- className: "inks-grid-item"
76
- }, item), idx);
92
+ return jsxRuntime.jsx(Pair, _extends({}, item, {
93
+ className: clsx("inks-grid-item", item.className)
94
+ }), idx);
77
95
  case "text":
78
- return jsxRuntime.jsx(Text, _extends({
79
- className: "inks-grid-item"
80
- }, item), idx);
96
+ return jsxRuntime.jsx(Text, _extends({}, item, {
97
+ className: clsx("inks-grid-item", item.className)
98
+ }), idx);
81
99
  }
82
100
  })
83
101
  });
@@ -220,12 +238,13 @@ var Pair = function Pair(_ref5) {
220
238
  })]
221
239
  });
222
240
  };
223
- var InkScripter = function InkScripter(props) {
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;
@@ -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: import("react").ForwardRefExoticComponent<IFrameProps & import("react").RefAttributes<HTMLIFrameElement>>;
9
+ export declare const IFrame: ForwardRefExoticComponent<IFrameProps & RefAttributes<any>>;
@@ -1,13 +1,14 @@
1
- /// <reference types="react" />
2
- import { ClassValue } from "clsx";
1
+ import type { ForwardRefExoticComponent, RefAttributes } from "react";
3
2
  export type ContentTextItem = {
4
3
  id?: string;
4
+ className?: string;
5
5
  type: "text";
6
6
  value: string;
7
7
  span?: number;
8
8
  };
9
9
  export type ContentPairItem = {
10
10
  id?: string;
11
+ className?: string;
11
12
  type: "pair";
12
13
  label: string;
13
14
  value: string;
@@ -20,6 +21,7 @@ export type ContentGridItem = {
20
21
  };
21
22
  export type ContentTableCellItem = {
22
23
  id?: string;
24
+ className?: string;
23
25
  header?: boolean;
24
26
  rowSpan?: number;
25
27
  colSpan?: number;
@@ -34,12 +36,9 @@ export type ContentTableItem = {
34
36
  };
35
37
  export type ContentItemType = ContentGridItem | ContentTableItem | ContentTextItem | ContentPairItem;
36
38
  export type ContentType = ContentItemType[];
37
- export type ReactInkScripterProps = {
39
+ export type InkScripterProps = {
38
40
  value?: ContentType;
39
41
  className?: string;
40
42
  };
41
- export type TypeWithClassName<T> = T & {
42
- className?: ClassValue;
43
- };
44
- export declare const InkScripter: (props: ReactInkScripterProps) => JSX.Element;
43
+ export declare const InkScripter: ForwardRefExoticComponent<InkScripterProps & RefAttributes<any>>;
45
44
  export default InkScripter;
@@ -1,4 +1,4 @@
1
- import { ReactNode, Ref } from "react";
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: (props: PrinterFrameProps) => JSX.Element;
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,15 +46,15 @@ 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) => {
47
53
  switch (item.type) {
48
54
  case "pair":
49
- return jsx(Pair, { className: "inks-grid-item", ...item }, idx);
55
+ return (jsx(Pair, { ...item, className: clsx("inks-grid-item", item.className) }, idx));
50
56
  case "text":
51
- return jsx(Text, { className: "inks-grid-item", ...item }, idx);
57
+ return (jsx(Text, { ...item, className: clsx("inks-grid-item", item.className) }, idx));
52
58
  }
53
59
  }) }));
54
60
  };
@@ -99,15 +105,15 @@ const Table = (props) => {
99
105
  }
100
106
  return (jsxs("table", { id: id, className: "inks-table", children: [jsx(TableHead, { rows: head }), jsx(TableBody, { rows: body }), jsx(TableFoot, { rows: foot })] }));
101
107
  };
102
- const Text = ({ id, value, span, className, }) => {
108
+ const Text = ({ id, value, span, className }) => {
103
109
  return (jsx("div", { id: id, className: clsx("inks-text", span && "inks-grid", span && `inks-span-${span}`, className), children: value }));
104
110
  };
105
- const Pair = ({ id, value, label, span, className, }) => {
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-ink-scripter",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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",