@pdfme/ui 5.3.17-dev.6 → 5.3.17-dev.7
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/index.es.js +18 -7
- package/dist/index.umd.js +2 -2
- package/dist/types/src/helper.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/Designer/LeftSidebar.tsx +8 -2
- package/src/helper.ts +18 -1
package/dist/index.es.js
CHANGED
@@ -80759,6 +80759,12 @@ const arrayBufferToBase64 = (a) => {
|
|
80759
80759
|
}, useMaxZoom = () => {
|
80760
80760
|
const a = reactExports.useContext(OptionsContext);
|
80761
80761
|
return a.maxZoom ? a.maxZoom / 100 : DEFAULT_MAX_ZOOM;
|
80762
|
+
}, setFontNameRecursively = (a, s, c = /* @__PURE__ */ new WeakSet()) => {
|
80763
|
+
if (!(!a || typeof a != "object" || c.has(a))) {
|
80764
|
+
c.add(a);
|
80765
|
+
for (const u in a)
|
80766
|
+
u === "fontName" && Object.prototype.hasOwnProperty.call(a, u) && a[u] === void 0 ? a[u] = s : typeof a[u] == "object" && a[u] !== null && setFontNameRecursively(a[u], s, c);
|
80767
|
+
}
|
80762
80768
|
};
|
80763
80769
|
class BaseUIClass {
|
80764
80770
|
constructor(s) {
|
@@ -153202,22 +153208,27 @@ const FormRenderComponent = withProvider(FormCore, defaultWidgets), AlignWidget
|
|
153202
153208
|
}, I), w ? /* @__PURE__ */ jsxRuntimeExports.jsx(Wrapper, { ...a, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: "100%", width: "100%" }, ref: C }) }) : (console.error(`[@pdfme/ui] Renderer for type ${s.type} not found.
|
153203
153209
|
Check this document: https://pdfme.com/docs/custom-schemas`), /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {}));
|
153204
153210
|
}, Draggable$1 = (a) => {
|
153205
|
-
const { scale: s, basePdf: c, plugin: u } = a, { token: d } = theme.useToken(), p =
|
153211
|
+
const { scale: s, basePdf: c, plugin: u } = a, { token: d } = theme.useToken(), p = reactExports.useContext(OptionsContext), v = u.propPanel.defaultSchema;
|
153212
|
+
if (p.font) {
|
153213
|
+
const S = getFallbackFontName(p.font);
|
153214
|
+
setFontNameRecursively(v, S);
|
153215
|
+
}
|
153216
|
+
const A = useDraggable({ id: v.type, data: v }), { listeners: b, setNodeRef: g, attributes: x, transform: y, isDragging: f } = A, m = { transform: CSS$1.Translate.toString(y) }, C = React.useMemo(() => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { transform: `scale(${s})` }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
153206
153217
|
Renderer,
|
153207
153218
|
{
|
153208
|
-
schema: { ...
|
153219
|
+
schema: { ...v, id: v.type },
|
153209
153220
|
basePdf: c,
|
153210
|
-
value:
|
153221
|
+
value: v.content || "",
|
153211
153222
|
onChangeHoveringSchemaId: () => {
|
153212
153223
|
},
|
153213
153224
|
mode: "viewer",
|
153214
153225
|
outline: `1px solid ${d.colorPrimary}`,
|
153215
153226
|
scale: s
|
153216
153227
|
}
|
153217
|
-
) }), [
|
153218
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ref:
|
153219
|
-
|
153220
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { visibility:
|
153228
|
+
) }), [v, c, s, d.colorPrimary]);
|
153229
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ref: g, style: m, ...b, ...x, children: [
|
153230
|
+
f && C,
|
153231
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { visibility: f ? "hidden" : "visible" }, children: a.children })
|
153221
153232
|
] });
|
153222
153233
|
}, LeftSidebar = ({
|
153223
153234
|
height: a,
|
package/dist/index.umd.js
CHANGED
@@ -183,7 +183,7 @@ endstream`,s}copyBytesInto(s,c){this.updateDict();const u=c;c+=this.dict.copyByt
|
|
183
183
|
* This source code is licensed under the ISC license.
|
184
184
|
* See the LICENSE file in the root directory of this source tree.
|
185
185
|
*/const Underline=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20"}]],TextStrikethroughIcon=createSvgStr(Strikethrough),TextUnderlineIcon=createSvgStr(Underline),TextAlignLeftIcon=createSvgStr(AlignLeft),TextAlignCenterIcon=createSvgStr(AlignCenter),TextAlignRightIcon=createSvgStr(AlignRight),TextAlignJustifyIcon=createSvgStr(AlignJustify),TextVerticalAlignTopIcon=createSvgStr(ArrowUpToLine),TextVerticalAlignMiddleIcon='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><path d="M8 19h3v4h2v-4h3l-4-4l-4 4zm8-14h-3V1h-2v4H8l4 4l4-4zM4 11v2h16v-2H4z" fill="currentColor"></path></svg>',TextVerticalAlignBottomIcon=createSvgStr(ArrowDownToLine);var Formatter;(function(a){a.STRIKETHROUGH="strikethrough",a.UNDERLINE="underline",a.ALIGNMENT="alignment",a.VERTICAL_ALIGNMENT="verticalAlignment"})(Formatter||(Formatter={}));function getExtraFormatterSchema(a){const s=[{key:Formatter.STRIKETHROUGH,icon:TextStrikethroughIcon,type:"boolean"},{key:Formatter.UNDERLINE,icon:TextUnderlineIcon,type:"boolean"},{key:Formatter.ALIGNMENT,icon:TextAlignLeftIcon,type:"select",value:DEFAULT_ALIGNMENT},{key:Formatter.ALIGNMENT,icon:TextAlignCenterIcon,type:"select",value:ALIGN_CENTER},{key:Formatter.ALIGNMENT,icon:TextAlignRightIcon,type:"select",value:ALIGN_RIGHT},{key:Formatter.ALIGNMENT,icon:TextAlignJustifyIcon,type:"select",value:ALIGN_JUSTIFY},{key:Formatter.VERTICAL_ALIGNMENT,icon:TextVerticalAlignTopIcon,type:"select",value:DEFAULT_VERTICAL_ALIGNMENT},{key:Formatter.VERTICAL_ALIGNMENT,icon:TextVerticalAlignMiddleIcon,type:"select",value:VERTICAL_ALIGN_MIDDLE},{key:Formatter.VERTICAL_ALIGNMENT,icon:TextVerticalAlignBottomIcon,type:"select",value:VERTICAL_ALIGN_BOTTOM}];return{title:a("schemas.text.format"),widget:"ButtonGroup",buttons:s,span:24}}const UseDynamicFontSize=a=>{const{rootElement:s,changeSchemas:c,activeSchema:u,i18n:d}=a,p=document.createElement("input");p.type="checkbox",p.checked=!!(u!=null&&u.dynamicFontSize),p.onchange=b=>{const g=b.target.checked?{min:DEFAULT_DYNAMIC_MIN_FONT_SIZE,max:DEFAULT_DYNAMIC_MAX_FONT_SIZE,fit:DEFAULT_DYNAMIC_FIT}:void 0;c([{key:"dynamicFontSize",value:g,schemaId:u.id}])};const v=document.createElement("label"),A=document.createElement("span");A.innerText=d("schemas.text.dynamicFontSize")||"",A.style.cssText="margin-left: 0.5rem",v.style.cssText="display: flex; width: 100%;",v.appendChild(p),v.appendChild(A),s.appendChild(v)},propPanel={schema:({options:a,activeSchema:s,i18n:c})=>{const u=a.font||{[DEFAULT_FONT_NAME]:{data:"",fallback:!0}},d=Object.keys(u),p=getFallbackFontName(u),v=!!(s!=null&&s.dynamicFontSize);return{fontName:{title:c("schemas.text.fontName"),type:"string",widget:"select",default:p,placeholder:p,props:{options:d.map(b=>({label:b,value:b}))},span:12},fontSize:{title:c("schemas.text.size"),type:"number",widget:"inputNumber",span:6,disabled:v,props:{min:0}},characterSpacing:{title:c("schemas.text.spacing"),type:"number",widget:"inputNumber",span:6,props:{min:0}},formatter:getExtraFormatterSchema(c),lineHeight:{title:c("schemas.text.lineHeight"),type:"number",widget:"inputNumber",props:{step:.1,min:0},span:8},useDynamicFontSize:{type:"boolean",widget:"UseDynamicFontSize",bind:!1,span:16},dynamicFontSize:{type:"object",widget:"card",column:3,properties:{min:{title:c("schemas.text.min"),type:"number",widget:"inputNumber",hidden:!v,props:{min:0}},max:{title:c("schemas.text.max"),type:"number",widget:"inputNumber",hidden:!v,props:{min:0}},fit:{title:c("schemas.text.fit"),type:"string",widget:"select",hidden:!v,props:{options:[{label:c("schemas.horizontal"),value:DYNAMIC_FIT_HORIZONTAL},{label:c("schemas.vertical"),value:DYNAMIC_FIT_VERTICAL}]}}}},fontColor:{title:c("schemas.textColor"),type:"string",widget:"color",props:{disabledAlpha:!0},rules:[{pattern:HEX_COLOR_PATTERN,message:c("validation.hexColor")}]},backgroundColor:{title:c("schemas.bgColor"),type:"string",widget:"color",props:{disabledAlpha:!0},rules:[{pattern:HEX_COLOR_PATTERN,message:c("validation.hexColor")}]}}},widgets:{UseDynamicFontSize},defaultSchema:{name:"",type:"text",content:"Type Something...",position:{x:0,y:0},width:45,height:10,rotate:0,alignment:DEFAULT_ALIGNMENT,verticalAlignment:DEFAULT_VERTICAL_ALIGNMENT,fontSize:DEFAULT_FONT_SIZE,lineHeight:DEFAULT_LINE_HEIGHT,characterSpacing:DEFAULT_CHARACTER_SPACING,dynamicFontSize:void 0,fontColor:DEFAULT_FONT_COLOR,fontName:void 0,backgroundColor:"",opacity:DEFAULT_OPACITY,strikethrough:!1,underline:!1}},replaceUnsupportedChars=(a,s)=>{const c={},u=p=>{if(p in c)return c[p];const v=s.hasGlyphForCodePoint(p.codePointAt(0)||0);return c[p]=v,v};return a.split(/(\r\n|\n|\r)/).map(p=>/\r\n|\n|\r/.test(p)?p:p.split("").map(v=>/\s/.test(v)||v.charCodeAt(0)<32||u(v)?v:"〿").join("")).join("")},uiRender=async a=>{const{value:s,schema:c,mode:u,onChange:d,stopEditing:p,tabIndex:v,placeholder:A,options:b,_cache:g}=a,x=isEditable(u,c)&&A&&!s,y=w=>{let _=w.innerText;return _.endsWith(`
|
186
|
-
`)&&(_=_.slice(0,-1)),_},f=(b==null?void 0:b.font)||getDefaultFont(),m=await getFontKitFont(c.fontName,f,g),C=buildStyledTextContainer(a,m,x?A:s),S=replaceUnsupportedChars(s,m);if(!isEditable(u,c)){C.innerHTML=S.split("").map((w,_)=>`<span style="letter-spacing:${String(s).length===_+1?0:"inherit"};">${w}</span>`).join("");return}if(makeElementPlainTextContentEditable(C),C.tabIndex=v||0,C.innerText=u==="designer"?s:S,C.addEventListener("blur",w=>{d&&d({key:"content",value:y(w.target)}),p&&p()}),c.dynamicFontSize){let w;C.addEventListener("keyup",()=>{setTimeout(()=>{(()=>{if(!C.textContent)return;w=calculateDynamicFontSize({textSchema:c,fontKitFont:m,value:y(C),startingFontSize:w}),C.style.fontSize=`${w}pt`;const{topAdj:_,bottomAdj:I}=getBrowserVerticalFontAdjustments(m,w??c.fontSize??DEFAULT_FONT_SIZE,c.lineHeight??DEFAULT_LINE_HEIGHT,c.verticalAlignment??DEFAULT_VERTICAL_ALIGNMENT);C.style.paddingTop=`${_}px`,C.style.marginBottom=`${I}px`})()},0)})}x&&(C.style.color=PLACEHOLDER_FONT_COLOR,C.addEventListener("focus",()=>{C.innerText===A&&(C.innerText="",C.style.color=c.fontColor??DEFAULT_FONT_COLOR)})),u==="designer"&&setTimeout(()=>{C.focus();const w=window.getSelection(),_=document.createRange();w&&_&&(_.selectNodeContents(C),_.collapse(!1),w==null||w.removeAllRanges(),w==null||w.addRange(_))})},buildStyledTextContainer=(a,s,c)=>{const{schema:u,rootElement:d,mode:p}=a;let v;u.dynamicFontSize&&c&&(v=calculateDynamicFontSize({textSchema:u,fontKitFont:s,value:c,startingFontSize:v}));const{topAdj:A,bottomAdj:b}=getBrowserVerticalFontAdjustments(s,v??u.fontSize??DEFAULT_FONT_SIZE,u.lineHeight??DEFAULT_LINE_HEIGHT,u.verticalAlignment??DEFAULT_VERTICAL_ALIGNMENT),g=A.toString(),x=b.toString(),y=document.createElement("div"),f={padding:0,resize:"none",backgroundColor:getBackgroundColor(c,u),border:"none",display:"flex",flexDirection:"column",justifyContent:mapVerticalAlignToFlex(u.verticalAlignment),width:"100%",height:"100%",cursor:isEditable(p,u)?"text":"default"};Object.assign(y.style,f),d.innerHTML="",d.appendChild(y);const m=[];u.strikethrough&&m.push("line-through"),u.underline&&m.push("underline");const C={fontFamily:u.fontName?`'${u.fontName}'`:"inherit",color:u.fontColor?u.fontColor:DEFAULT_FONT_COLOR,fontSize:`${v??u.fontSize??DEFAULT_FONT_SIZE}pt`,letterSpacing:`${u.characterSpacing??DEFAULT_CHARACTER_SPACING}pt`,lineHeight:`${u.lineHeight??DEFAULT_LINE_HEIGHT}em`,textAlign:u.alignment??DEFAULT_ALIGNMENT,whiteSpace:"pre-wrap",wordBreak:"break-word",resize:"none",border:"none",outline:"none",marginBottom:`${x}px`,paddingTop:`${g}px`,backgroundColor:"transparent",textDecoration:m.join(" ")},S=document.createElement("div");return S.id="text-"+String(u.id),Object.assign(S.style,C),y.appendChild(S),S},makeElementPlainTextContentEditable=a=>{if(!isFirefox()){a.contentEditable="plaintext-only";return}a.contentEditable="true",a.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),document.execCommand("insertLineBreak",!1,void 0))}),a.addEventListener("paste",s=>{var d;s.preventDefault();const c=(d=s.clipboardData)==null?void 0:d.getData("text"),u=window.getSelection();u!=null&&u.rangeCount&&(u.deleteFromDocument(),u.getRangeAt(0).insertNode(document.createTextNode(c||"")),u.collapseToEnd())})},mapVerticalAlignToFlex=a=>{switch(a){case VERTICAL_ALIGN_TOP:return"flex-start";case VERTICAL_ALIGN_MIDDLE:return"center";case VERTICAL_ALIGN_BOTTOM:return"flex-end"}return"flex-start"},getBackgroundColor=(a,s)=>!a||!s.backgroundColor?"transparent":s.backgroundColor,textSchema={pdf:pdfRender,ui:uiRender,propPanel,icon:createSvgStr(TextCursorInput)},builtInPlugins={Text:textSchema},I18nContext=reactExports.createContext(i18n),FontContext=reactExports.createContext(getDefaultFont()),PluginsRegistry=reactExports.createContext(pluginRegistry(builtInPlugins)),OptionsContext=reactExports.createContext({}),CacheContext=reactExports.createContext(new Map),hotkeys=function(a,s){return hotkeys$1(a,s)};hotkeys.shift=!1,hotkeys.unbind=function(a){const s=hotkeys$1;typeof s.unbind=="function"&&s.unbind(a)};const uuid$6=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const s=Math.random()*16|0;return(a=="x"?s:s&3|8).toString(16)}),set$2=(a,s,c)=>{s=Array.isArray(s)?s:s.replace("[",".").replace("]","").split(".");let u=a;s.forEach((d,p,v)=>{if(p==s.length-1)u[d]=c;else{if(!Object.prototype.hasOwnProperty.call(u,d)){const A=v[p+1];u[d]=String(Number(A))===A?[]:{}}u=u[d]}})},debounce$1=(a,s=20)=>{let c=null;return(...d)=>{c&&clearTimeout(c),c=setTimeout(()=>a(...d),s)}},shift=(a,s,c)=>{c&&(s=-s);const u=`${a}`.split("e");return+`${u[0]}e${u[1]?Number(u[1])+s:s}`},round$1=(a,s)=>shift(Math.round(shift(a,s,!1)),s,!0),flatten=a=>[].concat(...a),up="up",shiftUp="shift+up",down="down",shiftDown="shift+down",left="left",shiftLeft="shift+left",right="right",shiftRight="shift+right",rmWin="backspace",rmMac="delete",esc="esc",copyWin="ctrl+c",copyMac="command+c",pasteWin="ctrl+v",pasteMac="command+v",redoWin="ctrl+y",redoMac="shift+command+z",undoWin="ctrl+z",undoMac="command+z",saveWin="ctrl+s",saveMac="command+s",selectAllWin="ctrl+a",selectAllMac="command+a",keys$2=[up,shiftUp,down,shiftDown,left,shiftLeft,right,shiftRight,rmMac,rmWin,esc,copyWin,copyMac,pasteWin,pasteMac,redoWin,redoMac,undoWin,undoMac,saveWin,saveMac,selectAllWin,selectAllMac],initShortCuts=a=>{hotkeys(keys$2.join(),(s,c)=>{switch(c.shortcut){case up:case shiftUp:s.preventDefault(),a.move("up",hotkeys.shift);break;case down:case shiftDown:s.preventDefault(),a.move("down",hotkeys.shift);break;case left:case shiftLeft:s.preventDefault(),a.move("left",hotkeys.shift);break;case right:case shiftRight:s.preventDefault(),a.move("right",hotkeys.shift);break;case rmWin:case rmMac:a.remove();break;case esc:a.esc();break;case copyWin:case copyMac:a.copy();break;case pasteWin:case pasteMac:a.paste();break;case redoWin:case redoMac:a.redo();break;case undoWin:case undoMac:a.undo();break;case saveWin:case saveMac:s.preventDefault(),a.save();break;case selectAllWin:case selectAllMac:s.preventDefault(),a.selectAll();break}})},destroyShortCuts=()=>{hotkeys.unbind(keys$2.join())};function detectMimeType(a){const s=new DataView(a);return s.getUint8(0)===137&&s.getUint8(1)===80&&s.getUint8(2)===78&&s.getUint8(3)===71?"image/png":s.getUint8(0)===255&&s.getUint8(1)===216&&s.getUint8(2)===255?"image/jpeg":""}const arrayBufferToBase64=a=>{const s=detectMimeType(a),c=new Uint8Array(a);let u="";for(let p=0;p<c.length;p++)u+=String.fromCharCode(c[p]);const d=btoa(u);return s?`data:${s};base64,${d}`:`data:application/octet-stream;base64,${d}`},convertSchemasForUI=a=>(a.schemas.forEach(s=>{s.forEach(c=>{c.id=uuid$6(),c.content=c.content||""})}),a.schemas),template2SchemasList=async a=>{const s=cloneDeep$1(a),{basePdf:c,schemas:u}=s,d=convertSchemasForUI(s);let p=[];if(isBlankPdf(c))p=u.map(()=>({width:c.width,height:c.height}));else{const b=await getB64BasePdf(c),g=b64toUint8Array(b);p=await pdf2size(g)}const v=d.length,A=p.length;return(v<A?d.concat(new Array(A-v).fill(cloneDeep$1([]))):d.slice(0,p.length)).map((b,g)=>(Object.values(b).forEach(x=>{const{width:y,height:f}=p[g],m=x.position.x+x.width,C=x.position.y+x.height;if(y<m){const S=m-y;x.position.x+=S}if(f<C){const S=C-f;x.position.y+=S}}),b))},schemasList2template=(a,s)=>({schemas:cloneDeep$1(a).map(c=>c.map(u=>(delete u.id,u))),basePdf:s}),getUniqueSchemaName=a=>{const{copiedSchemaName:s,schema:c,stackUniqueSchemaNames:u}=a,d=c.map(g=>g.name).concat(u),p=d.reduce((g,x)=>Object.assign(g,{originalName:x,copiedNum:0}),{}),v=g=>g.replace(/ copy$| copy [0-9]*$/,"");d.filter(g=>/ copy$| copy [0-9]*$/.test(g)).forEach(g=>{const x=v(g),y=g.match(/[0-9]*$/),f=y&&y[0]?Number(y[0]):1;(p[x]??0)<f&&(p[x]=f)});const A=v(s);if(p[A]){const g=p[A],x=`${A} copy ${g+1}`;return u.push(x),x}const b=`${s} copy`;return u.push(b),b},moveCommandToChangeSchemasArg=a=>{const{command:s,activeSchemas:c,isShift:u,pageSize:d}=a,p=s==="up"||s==="down"?"y":"x",v=u?.1:1,A=b=>{let g=0;const{position:x}=b;switch(s){case"up":g=round$1(x.y-v,2);break;case"down":g=round$1(x.y+v,2);break;case"left":g=round$1(x.x-v,2);break;case"right":g=round$1(x.x+v,2);break}return g>0?g:0};return c.map(b=>{let g=A(b);const{width:x,height:y}=b;return p==="x"?g=g>d.width-x?round$1(d.width-x,2):g:g=g>d.height-y?round$1(d.height-y,2):g,{key:`position.${p}`,value:g,schemaId:b.id}})},getPagesScrollTopByIndex=(a,s,c)=>a.slice(0,s).reduce((u,d)=>u+(d.height*ZOOM+RULER_HEIGHT*c)*c,0),getSidebarContentHeight=a=>a-RULER_HEIGHT-RULER_HEIGHT/2-30,handlePositionSizeChange=(a,s,c,u,d)=>{const p=isBlankPdf(u)?u.padding:[0,0,0,0],[v,A,b,g]=p,{width:x,height:y}=d,f=(m,C,S)=>Math.min(Math.max(Number(m),C),S);s==="position.x"?a.position.x=f(c,g,x-a.width-A):s==="position.y"?a.position.y=f(c,v,y-a.height-b):s==="width"?a.width=f(c,0,x-a.position.x-A):s==="height"&&(a.height=f(c,0,y-a.position.y-b))},handleTypeChange=(a,s,c,u)=>{if(s!=="type")return;const d=["id","name","type","position","required"];Object.keys(a).forEach(v=>{d.includes(v)||delete a[v]});const p=u.findByType(c);if(p!=null&&p.propPanel.defaultSchema){const v=p.propPanel.defaultSchema,A=a;for(const b of Object.keys(v))if(!Object.prototype.hasOwnProperty.call(a,b)){const g=v[b];g!==void 0&&(A[b]=g)}}a.readOnly&&(a.required=!1)},changeSchemas=a=>{const{objs:s,schemas:c,basePdf:u,pluginsRegistry:d,pageSize:p,commitSchemas:v}=a,A=s.reduce((b,{key:g,value:x,schemaId:y})=>{const f=b.find(m=>m.id===y);return f&&(set$2(f,g,x),g==="type"?handleTypeChange(f,g,x,d):["position.x","position.y","width","height"].includes(g)&&handlePositionSizeChange(f,g,x,u,p)),b},cloneDeep$1(c));v(A)},useMaxZoom=()=>{const a=reactExports.useContext(OptionsContext);return a.maxZoom?a.maxZoom/100:DEFAULT_MAX_ZOOM};class BaseUIClass{constructor(s){this.lang=DEFAULT_LANG,this.font=getDefaultFont(),this.pluginsRegistry=pluginRegistry(builtInPlugins),this.options={},this.setSize=debounce$1(()=>{this.domContainer&&(this.size={height:this.domContainer.clientHeight||window.innerHeight,width:this.domContainer.clientWidth||window.innerWidth},this.render())},100),this.resizeObserver=new ResizeObserver(this.setSize),checkUIProps(s);const{domContainer:c,template:u,options:d={},plugins:p={}}=s;this.domContainer=c,this.template=cloneDeep$1(u),this.options=d,this.size={height:this.domContainer.clientHeight||window.innerHeight,width:this.domContainer.clientWidth||window.innerWidth},this.resizeObserver.observe(this.domContainer);const{lang:v,font:A}=d;v&&(this.lang=v),A&&(this.font=A),Object.values(p).length>0&&(this.pluginsRegistry=pluginRegistry(p))}getLang(){return this.lang}getFont(){return this.font}getPluginsRegistry(){return this.pluginsRegistry}getOptions(){return this.options}getTemplate(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);return this.template}updateTemplate(s){if(checkTemplate(s),!this.domContainer)throw Error(DESTROYED_ERR_MSG);this.template=cloneDeep$1(s),this.render()}updateOptions(s){checkUIOptions(s);const{lang:c,font:u}=s||{};c&&(this.lang=c),u&&(this.font=u),this.options=Object.assign(this.options,s),this.render()}destroy(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);ReactDOM.unmountComponentAtNode(this.domContainer),this.resizeObserver.unobserve(this.domContainer),this.domContainer=null}}class PreviewUI extends BaseUIClass{constructor(s){super(s),checkPreviewProps(s),this.inputs=convertToStingObjectArray(cloneDeep$1(s.inputs))}getInputs(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);return this.inputs}setInputs(s){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);checkInputs(s),this.inputs=convertToStingObjectArray(s),this.render()}}function convertToStingObjectArray(a){return a.map(s=>{const c={};return Object.keys(s).forEach(u=>{const d=s[u];Array.isArray(d)?c[u]=JSON.stringify(d):c[u]=d}),c})}function useCombinedRefs(){for(var a=arguments.length,s=new Array(a),c=0;c<a;c++)s[c]=arguments[c];return reactExports.useMemo(()=>u=>{s.forEach(d=>d(u))},s)}const canUseDOM=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function isWindow$4(a){const s=Object.prototype.toString.call(a);return s==="[object Window]"||s==="[object global]"}function isNode$1(a){return"nodeType"in a}function getWindow$1(a){var s,c;return a?isWindow$4(a)?a:isNode$1(a)&&(s=(c=a.ownerDocument)==null?void 0:c.defaultView)!=null?s:window:window}function isDocument(a){const{Document:s}=getWindow$1(a);return a instanceof s}function isHTMLElement(a){return isWindow$4(a)?!1:a instanceof getWindow$1(a).HTMLElement}function isSVGElement(a){return a instanceof getWindow$1(a).SVGElement}function getOwnerDocument(a){return a?isWindow$4(a)?a.document:isNode$1(a)?isDocument(a)?a:isHTMLElement(a)||isSVGElement(a)?a.ownerDocument:document:document:document}const useIsomorphicLayoutEffect$1=canUseDOM?reactExports.useLayoutEffect:reactExports.useEffect;function useEvent$1(a){const s=reactExports.useRef(a);return useIsomorphicLayoutEffect$1(()=>{s.current=a}),reactExports.useCallback(function(){for(var c=arguments.length,u=new Array(c),d=0;d<c;d++)u[d]=arguments[d];return s.current==null?void 0:s.current(...u)},[])}function useInterval(){const a=reactExports.useRef(null),s=reactExports.useCallback((u,d)=>{a.current=setInterval(u,d)},[]),c=reactExports.useCallback(()=>{a.current!==null&&(clearInterval(a.current),a.current=null)},[]);return[s,c]}function useLatestValue(a,s){s===void 0&&(s=[a]);const c=reactExports.useRef(a);return useIsomorphicLayoutEffect$1(()=>{c.current!==a&&(c.current=a)},s),c}function useLazyMemo(a,s){const c=reactExports.useRef();return reactExports.useMemo(()=>{const u=a(c.current);return c.current=u,u},[...s])}function useNodeRef(a){const s=useEvent$1(a),c=reactExports.useRef(null),u=reactExports.useCallback(d=>{d!==c.current&&(s==null||s(d,c.current)),c.current=d},[]);return[c,u]}function usePrevious$2(a){const s=reactExports.useRef();return reactExports.useEffect(()=>{s.current=a},[a]),s.current}let ids={};function useUniqueId(a,s){return reactExports.useMemo(()=>{if(s)return s;const c=ids[a]==null?0:ids[a]+1;return ids[a]=c,a+"-"+c},[a,s])}function createAdjustmentFn(a){return function(s){for(var c=arguments.length,u=new Array(c>1?c-1:0),d=1;d<c;d++)u[d-1]=arguments[d];return u.reduce((p,v)=>{const A=Object.entries(v);for(const[b,g]of A){const x=p[b];x!=null&&(p[b]=x+a*g)}return p},{...s})}}const add$1=createAdjustmentFn(1),subtract=createAdjustmentFn(-1);function hasViewportRelativeCoordinates(a){return"clientX"in a&&"clientY"in a}function isKeyboardEvent(a){if(!a)return!1;const{KeyboardEvent:s}=getWindow$1(a.target);return s&&a instanceof s}function isTouchEvent(a){if(!a)return!1;const{TouchEvent:s}=getWindow$1(a.target);return s&&a instanceof s}function getEventCoordinates(a){if(isTouchEvent(a)){if(a.touches&&a.touches.length){const{clientX:s,clientY:c}=a.touches[0];return{x:s,y:c}}else if(a.changedTouches&&a.changedTouches.length){const{clientX:s,clientY:c}=a.changedTouches[0];return{x:s,y:c}}}return hasViewportRelativeCoordinates(a)?{x:a.clientX,y:a.clientY}:null}const CSS$1=Object.freeze({Translate:{toString(a){if(!a)return;const{x:s,y:c}=a;return"translate3d("+(s?Math.round(s):0)+"px, "+(c?Math.round(c):0)+"px, 0)"}},Scale:{toString(a){if(!a)return;const{scaleX:s,scaleY:c}=a;return"scaleX("+s+") scaleY("+c+")"}},Transform:{toString(a){if(a)return[CSS$1.Translate.toString(a),CSS$1.Scale.toString(a)].join(" ")}},Transition:{toString(a){let{property:s,duration:c,easing:u}=a;return s+" "+c+"ms "+u}}}),SELECTOR="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function findFirstFocusableNode(a){return a.matches(SELECTOR)?a:a.querySelector(SELECTOR)}const hiddenStyles={display:"none"};function HiddenText(a){let{id:s,value:c}=a;return React.createElement("div",{id:s,style:hiddenStyles},c)}function LiveRegion(a){let{id:s,announcement:c,ariaLiveType:u="assertive"}=a;const d={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return React.createElement("div",{id:s,style:d,role:"status","aria-live":u,"aria-atomic":!0},c)}function useAnnouncement(){const[a,s]=reactExports.useState("");return{announce:reactExports.useCallback(u=>{u!=null&&s(u)},[]),announcement:a}}const DndMonitorContext=reactExports.createContext(null);function useDndMonitor(a){const s=reactExports.useContext(DndMonitorContext);reactExports.useEffect(()=>{if(!s)throw new Error("useDndMonitor must be used within a children of <DndContext>");return s(a)},[a,s])}function useDndMonitorProvider(){const[a]=reactExports.useState(()=>new Set),s=reactExports.useCallback(u=>(a.add(u),()=>a.delete(u)),[a]);return[reactExports.useCallback(u=>{let{type:d,event:p}=u;a.forEach(v=>{var A;return(A=v[d])==null?void 0:A.call(v,p)})},[a]),s]}const defaultScreenReaderInstructions={draggable:`
|
186
|
+
`)&&(_=_.slice(0,-1)),_},f=(b==null?void 0:b.font)||getDefaultFont(),m=await getFontKitFont(c.fontName,f,g),C=buildStyledTextContainer(a,m,x?A:s),S=replaceUnsupportedChars(s,m);if(!isEditable(u,c)){C.innerHTML=S.split("").map((w,_)=>`<span style="letter-spacing:${String(s).length===_+1?0:"inherit"};">${w}</span>`).join("");return}if(makeElementPlainTextContentEditable(C),C.tabIndex=v||0,C.innerText=u==="designer"?s:S,C.addEventListener("blur",w=>{d&&d({key:"content",value:y(w.target)}),p&&p()}),c.dynamicFontSize){let w;C.addEventListener("keyup",()=>{setTimeout(()=>{(()=>{if(!C.textContent)return;w=calculateDynamicFontSize({textSchema:c,fontKitFont:m,value:y(C),startingFontSize:w}),C.style.fontSize=`${w}pt`;const{topAdj:_,bottomAdj:I}=getBrowserVerticalFontAdjustments(m,w??c.fontSize??DEFAULT_FONT_SIZE,c.lineHeight??DEFAULT_LINE_HEIGHT,c.verticalAlignment??DEFAULT_VERTICAL_ALIGNMENT);C.style.paddingTop=`${_}px`,C.style.marginBottom=`${I}px`})()},0)})}x&&(C.style.color=PLACEHOLDER_FONT_COLOR,C.addEventListener("focus",()=>{C.innerText===A&&(C.innerText="",C.style.color=c.fontColor??DEFAULT_FONT_COLOR)})),u==="designer"&&setTimeout(()=>{C.focus();const w=window.getSelection(),_=document.createRange();w&&_&&(_.selectNodeContents(C),_.collapse(!1),w==null||w.removeAllRanges(),w==null||w.addRange(_))})},buildStyledTextContainer=(a,s,c)=>{const{schema:u,rootElement:d,mode:p}=a;let v;u.dynamicFontSize&&c&&(v=calculateDynamicFontSize({textSchema:u,fontKitFont:s,value:c,startingFontSize:v}));const{topAdj:A,bottomAdj:b}=getBrowserVerticalFontAdjustments(s,v??u.fontSize??DEFAULT_FONT_SIZE,u.lineHeight??DEFAULT_LINE_HEIGHT,u.verticalAlignment??DEFAULT_VERTICAL_ALIGNMENT),g=A.toString(),x=b.toString(),y=document.createElement("div"),f={padding:0,resize:"none",backgroundColor:getBackgroundColor(c,u),border:"none",display:"flex",flexDirection:"column",justifyContent:mapVerticalAlignToFlex(u.verticalAlignment),width:"100%",height:"100%",cursor:isEditable(p,u)?"text":"default"};Object.assign(y.style,f),d.innerHTML="",d.appendChild(y);const m=[];u.strikethrough&&m.push("line-through"),u.underline&&m.push("underline");const C={fontFamily:u.fontName?`'${u.fontName}'`:"inherit",color:u.fontColor?u.fontColor:DEFAULT_FONT_COLOR,fontSize:`${v??u.fontSize??DEFAULT_FONT_SIZE}pt`,letterSpacing:`${u.characterSpacing??DEFAULT_CHARACTER_SPACING}pt`,lineHeight:`${u.lineHeight??DEFAULT_LINE_HEIGHT}em`,textAlign:u.alignment??DEFAULT_ALIGNMENT,whiteSpace:"pre-wrap",wordBreak:"break-word",resize:"none",border:"none",outline:"none",marginBottom:`${x}px`,paddingTop:`${g}px`,backgroundColor:"transparent",textDecoration:m.join(" ")},S=document.createElement("div");return S.id="text-"+String(u.id),Object.assign(S.style,C),y.appendChild(S),S},makeElementPlainTextContentEditable=a=>{if(!isFirefox()){a.contentEditable="plaintext-only";return}a.contentEditable="true",a.addEventListener("keydown",s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),document.execCommand("insertLineBreak",!1,void 0))}),a.addEventListener("paste",s=>{var d;s.preventDefault();const c=(d=s.clipboardData)==null?void 0:d.getData("text"),u=window.getSelection();u!=null&&u.rangeCount&&(u.deleteFromDocument(),u.getRangeAt(0).insertNode(document.createTextNode(c||"")),u.collapseToEnd())})},mapVerticalAlignToFlex=a=>{switch(a){case VERTICAL_ALIGN_TOP:return"flex-start";case VERTICAL_ALIGN_MIDDLE:return"center";case VERTICAL_ALIGN_BOTTOM:return"flex-end"}return"flex-start"},getBackgroundColor=(a,s)=>!a||!s.backgroundColor?"transparent":s.backgroundColor,textSchema={pdf:pdfRender,ui:uiRender,propPanel,icon:createSvgStr(TextCursorInput)},builtInPlugins={Text:textSchema},I18nContext=reactExports.createContext(i18n),FontContext=reactExports.createContext(getDefaultFont()),PluginsRegistry=reactExports.createContext(pluginRegistry(builtInPlugins)),OptionsContext=reactExports.createContext({}),CacheContext=reactExports.createContext(new Map),hotkeys=function(a,s){return hotkeys$1(a,s)};hotkeys.shift=!1,hotkeys.unbind=function(a){const s=hotkeys$1;typeof s.unbind=="function"&&s.unbind(a)};const uuid$6=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{const s=Math.random()*16|0;return(a=="x"?s:s&3|8).toString(16)}),set$2=(a,s,c)=>{s=Array.isArray(s)?s:s.replace("[",".").replace("]","").split(".");let u=a;s.forEach((d,p,v)=>{if(p==s.length-1)u[d]=c;else{if(!Object.prototype.hasOwnProperty.call(u,d)){const A=v[p+1];u[d]=String(Number(A))===A?[]:{}}u=u[d]}})},debounce$1=(a,s=20)=>{let c=null;return(...d)=>{c&&clearTimeout(c),c=setTimeout(()=>a(...d),s)}},shift=(a,s,c)=>{c&&(s=-s);const u=`${a}`.split("e");return+`${u[0]}e${u[1]?Number(u[1])+s:s}`},round$1=(a,s)=>shift(Math.round(shift(a,s,!1)),s,!0),flatten=a=>[].concat(...a),up="up",shiftUp="shift+up",down="down",shiftDown="shift+down",left="left",shiftLeft="shift+left",right="right",shiftRight="shift+right",rmWin="backspace",rmMac="delete",esc="esc",copyWin="ctrl+c",copyMac="command+c",pasteWin="ctrl+v",pasteMac="command+v",redoWin="ctrl+y",redoMac="shift+command+z",undoWin="ctrl+z",undoMac="command+z",saveWin="ctrl+s",saveMac="command+s",selectAllWin="ctrl+a",selectAllMac="command+a",keys$2=[up,shiftUp,down,shiftDown,left,shiftLeft,right,shiftRight,rmMac,rmWin,esc,copyWin,copyMac,pasteWin,pasteMac,redoWin,redoMac,undoWin,undoMac,saveWin,saveMac,selectAllWin,selectAllMac],initShortCuts=a=>{hotkeys(keys$2.join(),(s,c)=>{switch(c.shortcut){case up:case shiftUp:s.preventDefault(),a.move("up",hotkeys.shift);break;case down:case shiftDown:s.preventDefault(),a.move("down",hotkeys.shift);break;case left:case shiftLeft:s.preventDefault(),a.move("left",hotkeys.shift);break;case right:case shiftRight:s.preventDefault(),a.move("right",hotkeys.shift);break;case rmWin:case rmMac:a.remove();break;case esc:a.esc();break;case copyWin:case copyMac:a.copy();break;case pasteWin:case pasteMac:a.paste();break;case redoWin:case redoMac:a.redo();break;case undoWin:case undoMac:a.undo();break;case saveWin:case saveMac:s.preventDefault(),a.save();break;case selectAllWin:case selectAllMac:s.preventDefault(),a.selectAll();break}})},destroyShortCuts=()=>{hotkeys.unbind(keys$2.join())};function detectMimeType(a){const s=new DataView(a);return s.getUint8(0)===137&&s.getUint8(1)===80&&s.getUint8(2)===78&&s.getUint8(3)===71?"image/png":s.getUint8(0)===255&&s.getUint8(1)===216&&s.getUint8(2)===255?"image/jpeg":""}const arrayBufferToBase64=a=>{const s=detectMimeType(a),c=new Uint8Array(a);let u="";for(let p=0;p<c.length;p++)u+=String.fromCharCode(c[p]);const d=btoa(u);return s?`data:${s};base64,${d}`:`data:application/octet-stream;base64,${d}`},convertSchemasForUI=a=>(a.schemas.forEach(s=>{s.forEach(c=>{c.id=uuid$6(),c.content=c.content||""})}),a.schemas),template2SchemasList=async a=>{const s=cloneDeep$1(a),{basePdf:c,schemas:u}=s,d=convertSchemasForUI(s);let p=[];if(isBlankPdf(c))p=u.map(()=>({width:c.width,height:c.height}));else{const b=await getB64BasePdf(c),g=b64toUint8Array(b);p=await pdf2size(g)}const v=d.length,A=p.length;return(v<A?d.concat(new Array(A-v).fill(cloneDeep$1([]))):d.slice(0,p.length)).map((b,g)=>(Object.values(b).forEach(x=>{const{width:y,height:f}=p[g],m=x.position.x+x.width,C=x.position.y+x.height;if(y<m){const S=m-y;x.position.x+=S}if(f<C){const S=C-f;x.position.y+=S}}),b))},schemasList2template=(a,s)=>({schemas:cloneDeep$1(a).map(c=>c.map(u=>(delete u.id,u))),basePdf:s}),getUniqueSchemaName=a=>{const{copiedSchemaName:s,schema:c,stackUniqueSchemaNames:u}=a,d=c.map(g=>g.name).concat(u),p=d.reduce((g,x)=>Object.assign(g,{originalName:x,copiedNum:0}),{}),v=g=>g.replace(/ copy$| copy [0-9]*$/,"");d.filter(g=>/ copy$| copy [0-9]*$/.test(g)).forEach(g=>{const x=v(g),y=g.match(/[0-9]*$/),f=y&&y[0]?Number(y[0]):1;(p[x]??0)<f&&(p[x]=f)});const A=v(s);if(p[A]){const g=p[A],x=`${A} copy ${g+1}`;return u.push(x),x}const b=`${s} copy`;return u.push(b),b},moveCommandToChangeSchemasArg=a=>{const{command:s,activeSchemas:c,isShift:u,pageSize:d}=a,p=s==="up"||s==="down"?"y":"x",v=u?.1:1,A=b=>{let g=0;const{position:x}=b;switch(s){case"up":g=round$1(x.y-v,2);break;case"down":g=round$1(x.y+v,2);break;case"left":g=round$1(x.x-v,2);break;case"right":g=round$1(x.x+v,2);break}return g>0?g:0};return c.map(b=>{let g=A(b);const{width:x,height:y}=b;return p==="x"?g=g>d.width-x?round$1(d.width-x,2):g:g=g>d.height-y?round$1(d.height-y,2):g,{key:`position.${p}`,value:g,schemaId:b.id}})},getPagesScrollTopByIndex=(a,s,c)=>a.slice(0,s).reduce((u,d)=>u+(d.height*ZOOM+RULER_HEIGHT*c)*c,0),getSidebarContentHeight=a=>a-RULER_HEIGHT-RULER_HEIGHT/2-30,handlePositionSizeChange=(a,s,c,u,d)=>{const p=isBlankPdf(u)?u.padding:[0,0,0,0],[v,A,b,g]=p,{width:x,height:y}=d,f=(m,C,S)=>Math.min(Math.max(Number(m),C),S);s==="position.x"?a.position.x=f(c,g,x-a.width-A):s==="position.y"?a.position.y=f(c,v,y-a.height-b):s==="width"?a.width=f(c,0,x-a.position.x-A):s==="height"&&(a.height=f(c,0,y-a.position.y-b))},handleTypeChange=(a,s,c,u)=>{if(s!=="type")return;const d=["id","name","type","position","required"];Object.keys(a).forEach(v=>{d.includes(v)||delete a[v]});const p=u.findByType(c);if(p!=null&&p.propPanel.defaultSchema){const v=p.propPanel.defaultSchema,A=a;for(const b of Object.keys(v))if(!Object.prototype.hasOwnProperty.call(a,b)){const g=v[b];g!==void 0&&(A[b]=g)}}a.readOnly&&(a.required=!1)},changeSchemas=a=>{const{objs:s,schemas:c,basePdf:u,pluginsRegistry:d,pageSize:p,commitSchemas:v}=a,A=s.reduce((b,{key:g,value:x,schemaId:y})=>{const f=b.find(m=>m.id===y);return f&&(set$2(f,g,x),g==="type"?handleTypeChange(f,g,x,d):["position.x","position.y","width","height"].includes(g)&&handlePositionSizeChange(f,g,x,u,p)),b},cloneDeep$1(c));v(A)},useMaxZoom=()=>{const a=reactExports.useContext(OptionsContext);return a.maxZoom?a.maxZoom/100:DEFAULT_MAX_ZOOM},setFontNameRecursively=(a,s,c=new WeakSet)=>{if(!(!a||typeof a!="object"||c.has(a))){c.add(a);for(const u in a)u==="fontName"&&Object.prototype.hasOwnProperty.call(a,u)&&a[u]===void 0?a[u]=s:typeof a[u]=="object"&&a[u]!==null&&setFontNameRecursively(a[u],s,c)}};class BaseUIClass{constructor(s){this.lang=DEFAULT_LANG,this.font=getDefaultFont(),this.pluginsRegistry=pluginRegistry(builtInPlugins),this.options={},this.setSize=debounce$1(()=>{this.domContainer&&(this.size={height:this.domContainer.clientHeight||window.innerHeight,width:this.domContainer.clientWidth||window.innerWidth},this.render())},100),this.resizeObserver=new ResizeObserver(this.setSize),checkUIProps(s);const{domContainer:c,template:u,options:d={},plugins:p={}}=s;this.domContainer=c,this.template=cloneDeep$1(u),this.options=d,this.size={height:this.domContainer.clientHeight||window.innerHeight,width:this.domContainer.clientWidth||window.innerWidth},this.resizeObserver.observe(this.domContainer);const{lang:v,font:A}=d;v&&(this.lang=v),A&&(this.font=A),Object.values(p).length>0&&(this.pluginsRegistry=pluginRegistry(p))}getLang(){return this.lang}getFont(){return this.font}getPluginsRegistry(){return this.pluginsRegistry}getOptions(){return this.options}getTemplate(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);return this.template}updateTemplate(s){if(checkTemplate(s),!this.domContainer)throw Error(DESTROYED_ERR_MSG);this.template=cloneDeep$1(s),this.render()}updateOptions(s){checkUIOptions(s);const{lang:c,font:u}=s||{};c&&(this.lang=c),u&&(this.font=u),this.options=Object.assign(this.options,s),this.render()}destroy(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);ReactDOM.unmountComponentAtNode(this.domContainer),this.resizeObserver.unobserve(this.domContainer),this.domContainer=null}}class PreviewUI extends BaseUIClass{constructor(s){super(s),checkPreviewProps(s),this.inputs=convertToStingObjectArray(cloneDeep$1(s.inputs))}getInputs(){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);return this.inputs}setInputs(s){if(!this.domContainer)throw Error(DESTROYED_ERR_MSG);checkInputs(s),this.inputs=convertToStingObjectArray(s),this.render()}}function convertToStingObjectArray(a){return a.map(s=>{const c={};return Object.keys(s).forEach(u=>{const d=s[u];Array.isArray(d)?c[u]=JSON.stringify(d):c[u]=d}),c})}function useCombinedRefs(){for(var a=arguments.length,s=new Array(a),c=0;c<a;c++)s[c]=arguments[c];return reactExports.useMemo(()=>u=>{s.forEach(d=>d(u))},s)}const canUseDOM=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function isWindow$4(a){const s=Object.prototype.toString.call(a);return s==="[object Window]"||s==="[object global]"}function isNode$1(a){return"nodeType"in a}function getWindow$1(a){var s,c;return a?isWindow$4(a)?a:isNode$1(a)&&(s=(c=a.ownerDocument)==null?void 0:c.defaultView)!=null?s:window:window}function isDocument(a){const{Document:s}=getWindow$1(a);return a instanceof s}function isHTMLElement(a){return isWindow$4(a)?!1:a instanceof getWindow$1(a).HTMLElement}function isSVGElement(a){return a instanceof getWindow$1(a).SVGElement}function getOwnerDocument(a){return a?isWindow$4(a)?a.document:isNode$1(a)?isDocument(a)?a:isHTMLElement(a)||isSVGElement(a)?a.ownerDocument:document:document:document}const useIsomorphicLayoutEffect$1=canUseDOM?reactExports.useLayoutEffect:reactExports.useEffect;function useEvent$1(a){const s=reactExports.useRef(a);return useIsomorphicLayoutEffect$1(()=>{s.current=a}),reactExports.useCallback(function(){for(var c=arguments.length,u=new Array(c),d=0;d<c;d++)u[d]=arguments[d];return s.current==null?void 0:s.current(...u)},[])}function useInterval(){const a=reactExports.useRef(null),s=reactExports.useCallback((u,d)=>{a.current=setInterval(u,d)},[]),c=reactExports.useCallback(()=>{a.current!==null&&(clearInterval(a.current),a.current=null)},[]);return[s,c]}function useLatestValue(a,s){s===void 0&&(s=[a]);const c=reactExports.useRef(a);return useIsomorphicLayoutEffect$1(()=>{c.current!==a&&(c.current=a)},s),c}function useLazyMemo(a,s){const c=reactExports.useRef();return reactExports.useMemo(()=>{const u=a(c.current);return c.current=u,u},[...s])}function useNodeRef(a){const s=useEvent$1(a),c=reactExports.useRef(null),u=reactExports.useCallback(d=>{d!==c.current&&(s==null||s(d,c.current)),c.current=d},[]);return[c,u]}function usePrevious$2(a){const s=reactExports.useRef();return reactExports.useEffect(()=>{s.current=a},[a]),s.current}let ids={};function useUniqueId(a,s){return reactExports.useMemo(()=>{if(s)return s;const c=ids[a]==null?0:ids[a]+1;return ids[a]=c,a+"-"+c},[a,s])}function createAdjustmentFn(a){return function(s){for(var c=arguments.length,u=new Array(c>1?c-1:0),d=1;d<c;d++)u[d-1]=arguments[d];return u.reduce((p,v)=>{const A=Object.entries(v);for(const[b,g]of A){const x=p[b];x!=null&&(p[b]=x+a*g)}return p},{...s})}}const add$1=createAdjustmentFn(1),subtract=createAdjustmentFn(-1);function hasViewportRelativeCoordinates(a){return"clientX"in a&&"clientY"in a}function isKeyboardEvent(a){if(!a)return!1;const{KeyboardEvent:s}=getWindow$1(a.target);return s&&a instanceof s}function isTouchEvent(a){if(!a)return!1;const{TouchEvent:s}=getWindow$1(a.target);return s&&a instanceof s}function getEventCoordinates(a){if(isTouchEvent(a)){if(a.touches&&a.touches.length){const{clientX:s,clientY:c}=a.touches[0];return{x:s,y:c}}else if(a.changedTouches&&a.changedTouches.length){const{clientX:s,clientY:c}=a.changedTouches[0];return{x:s,y:c}}}return hasViewportRelativeCoordinates(a)?{x:a.clientX,y:a.clientY}:null}const CSS$1=Object.freeze({Translate:{toString(a){if(!a)return;const{x:s,y:c}=a;return"translate3d("+(s?Math.round(s):0)+"px, "+(c?Math.round(c):0)+"px, 0)"}},Scale:{toString(a){if(!a)return;const{scaleX:s,scaleY:c}=a;return"scaleX("+s+") scaleY("+c+")"}},Transform:{toString(a){if(a)return[CSS$1.Translate.toString(a),CSS$1.Scale.toString(a)].join(" ")}},Transition:{toString(a){let{property:s,duration:c,easing:u}=a;return s+" "+c+"ms "+u}}}),SELECTOR="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function findFirstFocusableNode(a){return a.matches(SELECTOR)?a:a.querySelector(SELECTOR)}const hiddenStyles={display:"none"};function HiddenText(a){let{id:s,value:c}=a;return React.createElement("div",{id:s,style:hiddenStyles},c)}function LiveRegion(a){let{id:s,announcement:c,ariaLiveType:u="assertive"}=a;const d={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return React.createElement("div",{id:s,style:d,role:"status","aria-live":u,"aria-atomic":!0},c)}function useAnnouncement(){const[a,s]=reactExports.useState("");return{announce:reactExports.useCallback(u=>{u!=null&&s(u)},[]),announcement:a}}const DndMonitorContext=reactExports.createContext(null);function useDndMonitor(a){const s=reactExports.useContext(DndMonitorContext);reactExports.useEffect(()=>{if(!s)throw new Error("useDndMonitor must be used within a children of <DndContext>");return s(a)},[a,s])}function useDndMonitorProvider(){const[a]=reactExports.useState(()=>new Set),s=reactExports.useCallback(u=>(a.add(u),()=>a.delete(u)),[a]);return[reactExports.useCallback(u=>{let{type:d,event:p}=u;a.forEach(v=>{var A;return(A=v[d])==null?void 0:A.call(v,p)})},[a]),s]}const defaultScreenReaderInstructions={draggable:`
|
187
187
|
To pick up a draggable item, press the space bar.
|
188
188
|
While dragging, use the arrow keys to move the item.
|
189
189
|
Press space again to drop the item in its new position, or press escape to cancel.
|
@@ -879,7 +879,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
879
879
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _unsupportedIterableToArray$2(a,s){if(a){if(typeof a=="string")return _arrayLikeToArray$2(a,s);var c={}.toString.call(a).slice(8,-1);return c==="Object"&&a.constructor&&(c=a.constructor.name),c==="Map"||c==="Set"?Array.from(a):c==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray$2(a,s):void 0}}function _iterableToArray(a){if(typeof Symbol<"u"&&a[Symbol.iterator]!=null||a["@@iterator"]!=null)return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray$2(a)}function _arrayLikeToArray$2(a,s){(s==null||s>a.length)&&(s=a.length);for(var c=0,u=Array(s);c<s;c++)u[c]=a[c];return u}var TabPaneContent=function a(s){var c=s.renderCore,u=s.name,d=s.schema,p=s.rootPath;return reactExports.useMemo(function(){return React.createElement("div",{style:{flex:1}},c({schema:d,parentPath:[u],rootPath:[].concat(_toConsumableArray(p),[u])}))},[JSON.stringify(s)])},TabList=function a(s){var c=s.schema,u=s.fields,d=s.rootPath,p=s.renderCore,v=s.readOnly,A=s.delConfirmProps,b=s.tabName,g=s.hideDelete,x=s.hideAdd,y=s.addItem,f=s.removeItem,m=s.tabItemProps,C=m===void 0?{}:m,S=s.activeKey,w=__rest$15(s,["schema","fields","rootPath","renderCore","readOnly","delConfirmProps","tabName","hideDelete","hideAdd","addItem","removeItem","tabItemProps","activeKey"]),_=reactExports.useState("0"),I=_slicedToArray$2(_,2),$=I[0],P=I[1],E=reactExports.useContext(ConfigProvider.ConfigContext),R=translation(E);reactExports.useEffect(function(){P(S||"0")},[S]);var T=function(H){return b instanceof Array?b[H]||H+1:"".concat(b||R("item")," ").concat(H+1)},B=function(H){f(H),P("".concat(H>1?H-1:0))},M=function(H,j){if(j==="add"&&(!c.max||u.length<c.max)&&!v&&!x){y();var q=u.length;P("".concat(q))}},k=function(H){return!v&&!g?React.createElement(Popconfirm,Object.assign({onConfirm:function(){return B(H)}},A),React.createElement(_CloseOutlined,null)):React.createElement(React.Fragment,null)};return React.createElement(Tabs,Object.assign({className:"fr-tab-list",type:"editable-card"},w,{onChange:P,activeKey:"".concat($),onEdit:M,hideAdd:v||x}),u.map(function(O){var H=O.key,j=O.name;return React.createElement(Tabs.TabPane,Object.assign({key:H,className:"fr-list-item"},C,{tab:T(j),closeIcon:k(j)}),React.createElement(TabPaneContent,{name:j,rootPath:d,schema:c,renderCore:p}))}))};function _typeof(a){"@babel/helpers - typeof";return _typeof=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(s){return typeof s}:function(s){return s&&typeof Symbol=="function"&&s.constructor===Symbol&&s!==Symbol.prototype?"symbol":typeof s},_typeof(a)}function _defineProperty(a,s,c){return(s=_toPropertyKey(s))in a?Object.defineProperty(a,s,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[s]=c,a}function _toPropertyKey(a){var s=_toPrimitive(a,"string");return _typeof(s)=="symbol"?s:s+""}function _toPrimitive(a,s){if(_typeof(a)!="object"||!a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var u=c.call(a,s);if(_typeof(u)!="object")return u;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(a)}const index=function(a){var s=a.schema;return React.createElement("div",{className:classnames("fr-void-title",_defineProperty({},s==null?void 0:s.className,!!(s!=null&&s.className)))},s.title)};var ErrorSchema=function a(s){var c=reactExports.useContext(ConfigProvider.ConfigContext),u=translation(c);return React.createElement("div",null,React.createElement("div",{style:{color:"red"}},u("schema_not_match")),React.createElement("div",null,JSON.stringify(s)))};const defaultWidgets=Object.freeze(Object.defineProperty({__proto__:null,Card:BoxCard,CardList,Checkbox,Checkboxes:Checkboxes$1,Collapse:BoxCollapse,Color,DatePicker,DateRange:DateRange$1,DrawerList:TableList,ErrorSchema,Html:html,ImageInput:ImageInput$1,Input,InputNumber,LineTitle:FLineTitle,MultiSelect,PercentSlider,Radio,Rate:index$1,Select:MultiSelect,SimpleList,Slider,SubInline:BoxSubInline,Switch,TabList,TableList:TableList$1,TextArea:TextArea$1,TimePicker,TimeRange,TreeSelect,Upload:FrUpload,UrlInput:UrlInput$1,VirtualList,VoidTitle:index},Symbol.toStringTag,{value:"Module"}));function _slicedToArray$1(a,s){return _arrayWithHoles$1(a)||_iterableToArrayLimit$1(a,s)||_unsupportedIterableToArray$1(a,s)||_nonIterableRest$1()}function _nonIterableRest$1(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
880
880
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _unsupportedIterableToArray$1(a,s){if(a){if(typeof a=="string")return _arrayLikeToArray$1(a,s);var c={}.toString.call(a).slice(8,-1);return c==="Object"&&a.constructor&&(c=a.constructor.name),c==="Map"||c==="Set"?Array.from(a):c==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray$1(a,s):void 0}}function _arrayLikeToArray$1(a,s){(s==null||s>a.length)&&(s=a.length);for(var c=0,u=Array(s);c<s;c++)u[c]=a[c];return u}function _iterableToArrayLimit$1(a,s){var c=a==null?null:typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(c!=null){var u,d,p,v,A=[],b=!0,g=!1;try{if(p=(c=c.call(a)).next,s!==0)for(;!(b=(u=p.call(c)).done)&&(A.push(u.value),A.length!==s);b=!0);}catch(x){g=!0,d=x}finally{try{if(!b&&c.return!=null&&(v=c.return(),Object(v)!==v))return}finally{if(g)throw d}}return A}}function _arrayWithHoles$1(a){if(Array.isArray(a))return a}function flattenSchema(){var a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},s=arguments.length>1?arguments[1]:void 0,c=arguments.length>2?arguments[2]:void 0,u=arguments.length>3?arguments[3]:void 0,d=u||{},p=_cloneDeep(a)||{},v=s||"#";p.$id||(p.$id=v);var A=[];return isObjType(p)&&(sortProperties(Object.entries(p.properties)).forEach(function(b){var g=_slicedToArray$1(b,2),x=g[0],y=g[1],f=isListType(y)?x+"[]":x,m=v==="#"?f:v+"."+f;A.push(m),flattenSchema(y,m,v,d)}),p.properties={}),isListType(p)&&(sortProperties(Object.entries(p.items.properties)).forEach(function(b){var g=_slicedToArray$1(b,2),x=g[0],y=g[1],f=isListType(y)?x+"[]":x,m=v==="#"?f:v+"."+f;A.push(m),flattenSchema(y,m,v,d)}),p.items.properties={}),p.type&&(d[v]={parent:c,schema:p,children:A}),d}function _slicedToArray(a,s){return _arrayWithHoles(a)||_iterableToArrayLimit(a,s)||_unsupportedIterableToArray(a,s)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
881
881
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function _unsupportedIterableToArray(a,s){if(a){if(typeof a=="string")return _arrayLikeToArray(a,s);var c={}.toString.call(a).slice(8,-1);return c==="Object"&&a.constructor&&(c=a.constructor.name),c==="Map"||c==="Set"?Array.from(a):c==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,s):void 0}}function _arrayLikeToArray(a,s){(s==null||s>a.length)&&(s=a.length);for(var c=0,u=Array(s);c<s;c++)u[c]=a[c];return u}function _iterableToArrayLimit(a,s){var c=a==null?null:typeof Symbol<"u"&&a[Symbol.iterator]||a["@@iterator"];if(c!=null){var u,d,p,v,A=[],b=!0,g=!1;try{if(p=(c=c.call(a)).next,s!==0)for(;!(b=(u=p.call(c)).done)&&(A.push(u.value),A.length!==s);b=!0);}catch(x){g=!0,d=x}finally{try{if(!b&&c.return!=null&&(v=c.return(),Object(v)!==v))return}finally{if(g)throw d}}return A}}function _arrayWithHoles(a){if(Array.isArray(a))return a}var updateSchemaByPath=function a(s,c,u){var d=getSchemaFullPath(s,u),p=_get(u,d,{}),v=isFunction$1(c)?c(p):c,A=Object.assign(Object.assign({},p),v);v.props&&(A.props=Object.assign(Object.assign({},p==null?void 0:p.props),v.props)),_set(u,d,A)},getFieldName=function a(s){if(s){if(typeof s=="boolean")return s;var c=[];return isArray$1(s)&&(c=s.map(function(u){return u.split(".").map(function(d){return isNaN(Number(d))?d:d*1})})),c=s.split(".").map(function(u){return isNaN(Number(u))?u:u*1}),c=c.map(function(u){return typeof u=="string"&&(u==null?void 0:u.indexOf("["))===0&&(u==null?void 0:u.indexOf("]"))===(u==null?void 0:u.length)-1?Number(u.substring(1,u.length-1)):u}),c}},useForm=function a(){var s=Form$1.useForm(),c=_slicedToArray(s,1),u=c[0],d=reactExports.useRef({}),p=reactExports.useRef(null),v=reactExports.useRef({}),A=reactExports.useRef({});u.getFieldError;var b=u.getFieldsError,g=u.getFieldInstance,x=u.setFieldsValue,y=u.setFields,f=u.scrollToField,m=u.isFieldsTouched,C=u.isFieldTouched,S=u.isFieldValidating,w=u.resetFields,_=u.validateFields,I=__rest$15(u,["getFieldError","getFieldsError","getFieldInstance","setFieldsValue","setFields","scrollToField","isFieldsTouched","isFieldTouched","isFieldValidating","resetFields","validateFields"]),$=I,P=function(T){var B=p.current.setState;B||setTimeout(function(){B({schema:v.current,flattenSchema:d.current})},0),B(T)},E=function(T){d.current=flattenSchema(T)||{},v.current=T,P({schema:T,flattenSchema:d.current})};return $.setSchema=function(R){var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;if(isObject$2(R)){if(T){E(R);return}var B=cloneDeep(v.current);Object.keys(R||{}).forEach(function(M){updateSchemaByPath(M,R[M],B)}),E(B)}},$.setSchemaByPath=function(R,T){if(!(!_hasFuncProperty(T)&&_isMatch(T,$.getSchemaByPath(R)))){var B=cloneDeep(v.current);updateSchemaByPath(R,T,B),E(B)}},$.setValues=function(R){var T=parseBindToValues(R,d.current);x(T)},$.getValues=function(R,T,B){var M,k=cloneDeep(u.getFieldsValue(getFieldName(R),T)),O=((M=p.current)===null||M===void 0?void 0:M.getState())||{},H=O.removeHiddenData;return H&&(k=filterValuesHidden(k,d.current)),B||(k=filterValuesUndefined(k)),parseValuesToBind(k,d.current)},$.getValueByPath=function(R){var T=getFieldName(R);return u.getFieldValue(T)},$.setValueByPath=function(R,T){if(!u.setFieldValue){var B=u.getFieldsValue();_set(B,R,T),$.setValues(B);return}var M=getFieldName(R);u.setFieldValue(M,T);try{JSON.stringify(u.getFieldValue(M))!==JSON.stringify(T)&&u.setFieldValue(M,T)}catch{}},$.getSchemaByPath=function(R){typeof R!="string"&&console.warn("请输入正确的路径");var T=getSchemaFullPath(R,v.current);return _get(v.current,T)},$.getSchema=function(){return v.current},$.setErrorFields=function(R){var T=transformFieldsData(R,getFieldName);T&&y(T)},$.removeErrorField=function(R){y([{name:getFieldName(R),errors:[]}])},$.getFieldError=function(R){var T=getFieldName(R);return u.getFieldError(T)},$.getFieldsError=function(R){var T=getFieldName(R);return b(T)},$.getFieldInstance=function(R){var T=getFieldName(R);return g(T)},$.getHiddenValues=function(){var R=$.getValues(),T=$.getValues(!0),B={},M=function(O,H,j){Object.keys(O).forEach(function(q){var L=O[q],F=j?"".concat(j,".").concat(q):q;if(!H.hasOwnProperty(q)){_set(B,F,L);return}isObject$2(L)&&M(L,H[q],F),isArray$1(L)&&L.map(function(U,N){M(U,_get(H,"".concat(q,"[").concat(N,"]"),[]),"".concat(F,"[").concat(N,"]"))})})};return M(T,R,null),B},$.setFields=function(R){var T=transformFieldsData(R,getFieldName);T&&y(T)},$.__initStore=function(R){p.current=R},$.scrollToPath=function(R){for(var T=getFieldName(R),B=arguments.length,M=new Array(B>1?B-1:0),k=1;k<B;k++)M[k-1]=arguments[k];f.apply(void 0,[T].concat(M))},$.isFieldsTouched=function(R,T){var B=(R||[]).map(function(M){return getFieldName(M)});return m(B,T)},$.isFieldTouched=function(R){var T=getFieldName(R);return C(T)},$.isFieldValidating=function(R){var T=getFieldName(R);return S(T)},$.resetFields=function(R){var T=(R||[]).map(function(B){return getFieldName(B)});T.length>0?w(T):w()},$.validateFields=function(R,T){var B=(R||[]).map(function(M){return getFieldName(M)});return B.length>0?_(B,T):_()},$.getFlattenSchema=function(R){var T;return R?(T=d.current)===null||T===void 0?void 0:T[R]:d.current},$.onItemChange=$.setValueByPath,$.setFieldRef=function(R,T){R&&(A.current[R]=T)},$.getFieldRef=function(R){return A.current[R]},$};const FormRenderComponent=withProvider(FormCore,defaultWidgets),AlignWidget=a=>{const{activeElements:s,changeSchemas:c,schemas:u,pageSize:d,schema:p}=a,v=g=>{const x=s.map(E=>E.id),y=u.filter(E=>x.includes(E.id)),f=["left","center","right"].includes(g),m=f?"x":"y",C=f?"width":"height",S=y.length===1,w=d&&typeof d=="object"?C==="width"?d.width:d.height:0,_=S?0:Math.min(...y.map(E=>{const R=E.position&&typeof E.position=="object"?E.position:{x:0,y:0};return m==="x"?R.x:R.y})),I=S?w:Math.max(...y.map(E=>{const R=E.position&&typeof E.position=="object"?E.position:{x:0,y:0},T=m==="x"?R.x:R.y,B=E,M=C==="width"?B.width||0:B.height||0;return T+M}));let $=_,P=E=>0;["center","middle"].includes(g)?($=(_+I)/2,P=E=>E/2):["right","bottom"].includes(g)&&($=I,P=E=>E),c(y.map(E=>{const R=E,T=C==="width"?R.width||0:R.height||0;return{key:`position.${m}`,value:round$1($-P(T),2),schemaId:R.id}}))},A=g=>{const x=s.map(T=>T.id),y=u.filter(T=>x.includes(T.id)),f=g==="vertical",m=f?"y":"x",C=f?"height":"width",S=Math.min(...y.map(T=>{const B=T.position&&typeof T.position=="object"?T.position:{x:0,y:0};return m==="x"?B.x:B.y})),w=Math.max(...y.map(T=>{const B=T.position&&typeof T.position=="object"?T.position:{x:0,y:0},M=m==="x"?B.x:B.y,k=T,O=C==="width"?k.width||0:k.height||0;return M+O}));if(y.length<3)return;const _=S,I=w-S,$=y.reduce((T,B)=>{const M=B,k=C==="width"?M.width||0:M.height||0;return T+k},0),E=(I-$)/(y.length-1);let R=0;c(y.map((T,B)=>{const M=B===0?0:(()=>{const H=y[B-1];return C==="width"?H.width||0:H.height||0})();R+=B===0?0:M+E;const k=round$1(_+R,2),O=T;return{key:`position.${m}`,value:k,schemaId:O.id}}))},b=[{id:"left",icon:jsxRuntimeExports.jsx(AlignStartVertical,{size:15}),onClick:()=>v("left")},{id:"center",icon:jsxRuntimeExports.jsx(AlignCenterVertical,{size:15}),onClick:()=>v("center")},{id:"right",icon:jsxRuntimeExports.jsx(AlignEndVertical,{size:15}),onClick:()=>v("right")},{id:"top",icon:jsxRuntimeExports.jsx(AlignStartHorizontal,{size:15}),onClick:()=>v("top")},{id:"middle",icon:jsxRuntimeExports.jsx(AlignCenterHorizontal,{size:15}),onClick:()=>v("middle")},{id:"bottom",icon:jsxRuntimeExports.jsx(AlignEndHorizontal,{size:15}),onClick:()=>v("bottom")},{id:"vertical",icon:jsxRuntimeExports.jsx(AlignVerticalSpaceAround,{size:15}),onClick:()=>A("vertical")},{id:"horizontal",icon:jsxRuntimeExports.jsx(AlignHorizontalSpaceAround,{size:15}),onClick:()=>A("horizontal")}];return jsxRuntimeExports.jsx(Form$1.Item,{label:p.title,children:jsxRuntimeExports.jsx(Space.Compact,{children:b.map(g=>jsxRuntimeExports.jsx(Button$1,{style:{padding:7},disabled:s.length<=2&&["vertical","horizontal"].includes(g.id),...g},g.id))})})},WidgetRenderer=a=>{const{widget:s,...c}=a,u=reactExports.useRef(null);return reactExports.useEffect(()=>(u.current&&(u.current.innerHTML="",s({...c,rootElement:u.current})),()=>{u.current&&(u.current.innerHTML="")}),[a.activeSchema]),jsxRuntimeExports.jsx("div",{ref:u})},ButtonGroupWidget=a=>{const{activeElements:s,changeSchemas:c,schemas:u,schema:d}=a,{token:p}=theme.useToken(),v=x=>{const y=x.key,f=x.type,m=s.map(S=>S.id),C=u.filter(S=>m.includes(S.id));c(C.map(S=>{const w=!!(S[y]??!1),_=f==="boolean"?!w:x.value;return{key:y,value:_,schemaId:S.id}}))},A=x=>{const y=x.key,f=x.type;let m=!1;const C=s.map(w=>w.id);return u.filter(w=>C.includes(w.id)).forEach(w=>{const _=w;m=f==="boolean"?!!(_[y]??!1):_[y]===x.value}),m},b=(x,y)=>y?x.replace(/="currentColor"/g,`="${y}"`):x,g=x=>{const y=`data:image/svg+xml;utf8,${encodeURIComponent(b(x,p.colorText))}`;return jsxRuntimeExports.jsx("img",{width:17,height:17,src:y,alt:""})};return jsxRuntimeExports.jsx(Form$1.Item,{children:jsxRuntimeExports.jsx(Space.Compact,{children:d.buttons.map((x,y)=>{const f=A(x);return jsxRuntimeExports.jsx(Button$1,{type:f?"primary":void 0,ghost:f,onClick:()=>v(x),style:{padding:7,zIndex:f?2:0},icon:g(x.icon)},y)})})})},{Text:Text$2}=Typography,DetailView=a=>{var B;const{token:s}=theme.useToken(),{size:c,schemasList:u,changeSchemas:d,deselectSchema:p,activeSchema:v}=a,A=useForm(),b=reactExports.useContext(I18nContext),g=reactExports.useContext(PluginsRegistry),x=reactExports.useContext(OptionsContext),y=M=>typeof b=="function"?b(M):M,[f,m]=reactExports.useState({});reactExports.useEffect(()=>{const M={AlignWidget:k=>jsxRuntimeExports.jsx(AlignWidget,{...k,...a,options:x}),Divider:()=>jsxRuntimeExports.jsx(Divider,{style:{marginTop:s.marginXS,marginBottom:s.marginXS}}),ButtonGroup:k=>jsxRuntimeExports.jsx(ButtonGroupWidget,{...k,...a,options:x})};for(const k of g.values()){const O=k.propPanel.widgets||{};Object.entries(O).forEach(([H,j])=>{M[H]=q=>jsxRuntimeExports.jsx(WidgetRenderer,{...q,...a,options:x,theme:s,i18n:y,widget:j})})}m(M)},[v,g,JSON.stringify(x)]),reactExports.useEffect(()=>{const M={...v},k=typeof M.readOnly=="boolean"?M.readOnly:!1;M.editable=!k,A.setValues(M)},[v,A]),reactExports.useEffect(()=>A.resetFields(),[v.id]),reactExports.useEffect(()=>{C.current=M=>{for(const k of u)for(const O of Object.values(k))if(O.name===M&&O.id!==v.id)return!1;return!0}},[u,v]);const C=reactExports.useRef(M=>!0),S=(M,k)=>C.current(k),w=debounce$1(function(...M){const k=M[0],O=(j,q)=>typeof j=="object"&&j!==null?JSON.stringify(j)!==JSON.stringify(q):j!==q;let H=[];for(const j in k){if(["id","content"].includes(j))continue;let q=k[j];if(O(q,v[j])){if(q===null&&["rotate","opacity"].includes(j)&&(q=void 0),j==="editable"){const L=!q;H.push({key:"readOnly",value:L,schemaId:v.id}),L&&H.push({key:"required",value:!1,schemaId:v.id});continue}H.push({key:j,value:q,schemaId:v.id})}}H.length&&A.validateFields().then(()=>d(H)).catch(j=>{j.errorFields.length&&(H=H.filter(q=>!j.errorFields.find(L=>L.name.includes(q.key)))),H.length&&d(H)})},100),_=g.findByType(v.type);if(!_)throw Error(`[@pdfme/ui] Failed to find plugin used for ${v.type}`);const I=_.propPanel.schema,$=[];g.entries().forEach(([M,k])=>{var O;$.push({label:M,value:((O=k.propPanel.defaultSchema)==null?void 0:O.type)??void 0})});const P={},E=(B=_==null?void 0:_.propPanel)!=null&&B.defaultSchema?(()=>{const M={};for(const k in _.propPanel.defaultSchema)Object.prototype.hasOwnProperty.call(_.propPanel.defaultSchema,k)&&(M[k]=_.propPanel.defaultSchema[k]);return M})():P,R={type:"object",column:2,properties:{type:{title:y("type"),type:"string",widget:"select",props:{options:$},required:!0,span:12},name:{title:y("fieldName"),type:"string",required:!0,span:12,rules:[{validator:S,message:y("validation.uniqueName")}],props:{autoComplete:"off"}},editable:{title:y("editable"),type:"boolean",span:8,hidden:typeof E.readOnly<"u"},required:{title:y("required"),type:"boolean",span:16,hidden:"{{!formData.editable}}"},"-":{type:"void",widget:"Divider"},align:{title:y("align"),type:"void",widget:"AlignWidget"},position:{type:"object",widget:"card",properties:{x:{title:"X",type:"number",widget:"inputNumber",required:!0,span:8,min:0},y:{title:"Y",type:"number",widget:"inputNumber",required:!0,span:8,min:0}}},width:{title:y("width"),type:"number",widget:"inputNumber",required:!0,span:6,props:{min:0}},height:{title:y("height"),type:"number",widget:"inputNumber",required:!0,span:6,props:{min:0}},rotate:{title:y("rotate"),type:"number",widget:"inputNumber",disabled:typeof E.rotate>"u",max:360,props:{min:0},span:6},opacity:{title:y("opacity"),type:"number",widget:"inputNumber",disabled:typeof E.opacity>"u",props:{step:.1,min:0,max:1},span:6}}},T={...R.properties};if(typeof I=="function"){const{size:M,schemas:k,pageSize:O,changeSchemas:H,activeElements:j,deselectSchema:q,activeSchema:L}=a,U=I({...{size:M,schemas:k,pageSize:O,changeSchemas:H,activeElements:j,deselectSchema:q,activeSchema:L},options:x,theme:s,i18n:y}),N=U&&typeof U=="object"?U:{},D=Object.keys(N).length===0?{}:{"--":{type:"void",widget:"Divider"}};R.properties={...T,...D,...N}}else{const M=I&&typeof I=="object"?I:{},k=Object.keys(M).length===0?{}:{"--":{type:"void",widget:"Divider"}};R.properties={...T,...k,...M}}return jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsxs("div",{style:{height:40,display:"flex",alignItems:"center"},children:[jsxRuntimeExports.jsx(Button$1,{style:{position:"absolute",zIndex:100,display:"flex",alignItems:"center",justifyContent:"center"},onClick:p,icon:jsxRuntimeExports.jsx(Menu,{strokeWidth:1.5,size:20})}),jsxRuntimeExports.jsx(Text$2,{strong:!0,style:{textAlign:"center",width:"100%"},children:y("editField")})]}),jsxRuntimeExports.jsx(Divider,{style:{marginTop:s.marginXS,marginBottom:s.marginXS}}),jsxRuntimeExports.jsx("div",{style:{height:getSidebarContentHeight(c.height),overflowY:"auto",overflowX:"hidden"},children:jsxRuntimeExports.jsx(FormRenderComponent,{form:A,schema:R,widgets:f,watch:{"#":w},locale:"en-US"})})]})},propsAreUnchanged=(a,s)=>JSON.stringify(a.activeSchema)==JSON.stringify(s.activeSchema),DetailView$1=React.memo(DetailView,propsAreUnchanged),Sidebar=a=>{const{sidebarOpen:s,setSidebarOpen:c,activeElements:u,schemas:d}=a,{token:p}=theme.useToken(),v=()=>d.filter(g=>u.map(x=>x.id).includes(g.id)),A=()=>{const g=v();return g[g.length-1]},b={strokeWidth:1.5,size:20};return jsxRuntimeExports.jsx("div",{style:{position:"absolute",right:0,zIndex:1,height:"100%",width:s?RIGHT_SIDEBAR_WIDTH:0},children:jsxRuntimeExports.jsxs("div",{children:[jsxRuntimeExports.jsx(Button$1,{style:{position:"absolute",display:"flex",alignItems:"center",justifyContent:"center",top:"1rem",right:"1rem",zIndex:100},icon:s?jsxRuntimeExports.jsx(ArrowRight,{...b}):jsxRuntimeExports.jsx(ArrowLeft,{...b}),onClick:()=>c(!s)}),jsxRuntimeExports.jsx("div",{style:{width:RIGHT_SIDEBAR_WIDTH,height:"100%",display:s?"block":"none",top:0,right:0,position:"absolute",padding:"0.7rem 1rem",overflowY:"auto",fontFamily:"'Open Sans', sans-serif",boxSizing:"border-box",background:p.colorBgLayout},children:jsxRuntimeExports.jsx("div",{children:v().length===0?jsxRuntimeExports.jsx(ListView,{...a}):jsxRuntimeExports.jsx(DetailView$1,{...a,activeSchema:A()})})})]})})},useRerenderDependencies=a=>{const{plugin:s,value:c,mode:u,scale:d,schema:p,options:v}=a,A=cloneDeep$1(v);A.font&&Object.values(A.font).forEach(g=>{g.data="..."});const b=JSON.stringify(A);return reactExports.useMemo(()=>s!=null&&s.uninterruptedEditMode&&u==="designer"?[u]:[c,u,d,JSON.stringify(p),b],[c,u,d,p,b,s])},Wrapper=({children:a,outline:s,onChangeHoveringSchemaId:c,schema:u,selectable:d=!0})=>jsxRuntimeExports.jsxs("div",{title:u.name,onMouseEnter:()=>c&&c(u.id),onMouseLeave:()=>c&&c(null),className:d?SELECTABLE_CLASSNAME:"",id:u.id,style:{position:"absolute",cursor:u.readOnly?"initial":"pointer",height:u.height*ZOOM,width:u.width*ZOOM,top:u.position.y*ZOOM,left:u.position.x*ZOOM,transform:`rotate(${u.rotate??0}deg)`,opacity:u.opacity??1,outline:s},children:[u.required&&jsxRuntimeExports.jsx("span",{style:{color:"red",position:"absolute",top:-12,left:-12,fontSize:18,fontWeight:700},children:"*"}),a]}),Renderer=a=>{const{schema:s,basePdf:c,value:u,mode:d,onChange:p,stopEditing:v,tabIndex:A,placeholder:b,scale:g}=a,x=reactExports.useContext(PluginsRegistry),y=reactExports.useContext(OptionsContext),f=reactExports.useContext(I18nContext),{token:m}=theme.useToken(),C=reactExports.useRef(null),S=reactExports.useContext(CacheContext),w=x.findByType(s.type),_=useRerenderDependencies({plugin:w,value:u,mode:d,scale:g,schema:s,options:y});return reactExports.useEffect(()=>{if(!(w!=null&&w.ui)||!C.current||!s.type)return;C.current.innerHTML="";const I=w.ui;return I({value:u,schema:s,basePdf:c,rootElement:C.current,mode:d,onChange:p,stopEditing:v,tabIndex:A,placeholder:b,options:y,theme:m,i18n:f,_cache:S}),()=>{C.current&&(C.current.innerHTML="")}},_),w?jsxRuntimeExports.jsx(Wrapper,{...a,children:jsxRuntimeExports.jsx("div",{style:{height:"100%",width:"100%"},ref:C})}):(console.error(`[@pdfme/ui] Renderer for type ${s.type} not found.
|
882
|
-
Check this document: https://pdfme.com/docs/custom-schemas`),jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment,{}))},Draggable$1=a=>{const{scale:s,basePdf:c,plugin:u}=a,{token:d}=theme.useToken(),p=u.propPanel.defaultSchema,
|
882
|
+
Check this document: https://pdfme.com/docs/custom-schemas`),jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment,{}))},Draggable$1=a=>{const{scale:s,basePdf:c,plugin:u}=a,{token:d}=theme.useToken(),p=reactExports.useContext(OptionsContext),v=u.propPanel.defaultSchema;if(p.font){const S=getFallbackFontName(p.font);setFontNameRecursively(v,S)}const A=useDraggable({id:v.type,data:v}),{listeners:b,setNodeRef:g,attributes:x,transform:y,isDragging:f}=A,m={transform:CSS$1.Translate.toString(y)},C=React.useMemo(()=>jsxRuntimeExports.jsx("div",{style:{transform:`scale(${s})`},children:jsxRuntimeExports.jsx(Renderer,{schema:{...v,id:v.type},basePdf:c,value:v.content||"",onChangeHoveringSchemaId:()=>{},mode:"viewer",outline:`1px solid ${d.colorPrimary}`,scale:s})}),[v,c,s,d.colorPrimary]);return jsxRuntimeExports.jsxs("div",{ref:g,style:m,...b,...x,children:[f&&C,jsxRuntimeExports.jsx("div",{style:{visibility:f?"hidden":"visible"},children:a.children})]})},LeftSidebar=({height:a,scale:s,basePdf:c})=>{const{token:u}=theme.useToken(),d=reactExports.useContext(PluginsRegistry),[p,v]=reactExports.useState(!1);return reactExports.useEffect(()=>{const A=()=>{p&&v(!1)};return document.addEventListener("mouseup",A),()=>{document.removeEventListener("mouseup",A)}},[p]),jsxRuntimeExports.jsx("div",{style:{left:0,right:0,position:"absolute",zIndex:1,height:a,width:LEFT_SIDEBAR_WIDTH,background:u.colorBgLayout,textAlign:"center",overflow:p?"visible":"auto"},children:d.entries().map(([A,b])=>b!=null&&b.propPanel.defaultSchema?jsxRuntimeExports.jsx(Draggable$1,{scale:s,basePdf:c,plugin:b,children:jsxRuntimeExports.jsx(Button$1,{onMouseDown:()=>v(!0),style:{width:35,height:35,marginTop:"0.25rem",padding:"0.25rem"},children:jsxRuntimeExports.jsx(PluginIcon,{plugin:b,label:A})})},A):null)})},Paper=a=>{const{paperRefs:s,scale:c,size:u,schemasList:d,pageSizes:p,backgrounds:v,renderPaper:A,renderSchema:b,hasRulers:g}=a,x=reactExports.useContext(FontContext),y=g?RULER_HEIGHT:0;return p.length!==v.length||p.length!==d.length?null:jsxRuntimeExports.jsx("div",{style:{transform:`scale(${c})`,transformOrigin:"top left",height:c,width:c},children:v.map((f,m)=>{const C=p[m],S={width:C.width*ZOOM,height:C.height*ZOOM},w=S.width*c+y<u.width?`${(u.width/c-S.width)/2}px`:`${y}px`;let _=m>0?(y+PAGE_GAP)*(m+1):y;return g||(_+=PAGE_GAP*2),jsxRuntimeExports.jsxs("div",{ref:I=>{I&&(s.current[m]=I)},onMouseDown:I=>{I.currentTarget===I.target&&document&&document.hasFocus()&&document.activeElement instanceof HTMLElement&&document.activeElement.blur()},style:{fontFamily:`'${getFallbackFontName(x)}'`,top:`${_}px`,left:w,position:"relative",backgroundImage:`url(${f})`,backgroundSize:`${S.width}px ${S.height}px`,...S},children:[A({paperSize:S,index:m}),d[m].map((I,$)=>jsxRuntimeExports.jsx("div",{children:b({schema:I,index:m===0?$:$+d[m-1].length})},I.id))]},String(m)+JSON.stringify(S))})})};var FUNCTION="function",OBJECT="object",STRING="string",NUMBER="number",UNDEFINED="undefined",IS_WINDOW=typeof window!==UNDEFINED,doc=typeof document!==UNDEFINED&&document,OPEN_CLOSED_CHARACTERS=[{open:"(",close:")"},{open:'"',close:'"'},{open:"'",close:"'"},{open:'\\"',close:'\\"'},{open:"\\'",close:"\\'"}],TINY_NUM$1=1e-7,DEFAULT_UNIT_PRESETS={cm:function(a){return a*96/2.54},mm:function(a){return a*96/254},in:function(a){return a*96},pt:function(a){return a*96/72},pc:function(a){return a*96/6},"%":function(a,s){return a*s/100},vw:function(a,s){return s===void 0&&(s=window.innerWidth),a/100*s},vh:function(a,s){return s===void 0&&(s=window.innerHeight),a/100*s},vmax:function(a,s){return s===void 0&&(s=Math.max(window.innerWidth,window.innerHeight)),a/100*s},vmin:function(a,s){return s===void 0&&(s=Math.min(window.innerWidth,window.innerHeight)),a/100*s}};/*! *****************************************************************************
|
883
883
|
Copyright (c) Microsoft Corporation.
|
884
884
|
|
885
885
|
Permission to use, copy, modify, and/or distribute this software for any
|
@@ -71,3 +71,4 @@ export declare const changeSchemas: (args: {
|
|
71
71
|
commitSchemas: (newSchemas: SchemaForUI[]) => void;
|
72
72
|
}) => void;
|
73
73
|
export declare const useMaxZoom: () => number;
|
74
|
+
export declare const setFontNameRecursively: (obj: Record<string, unknown>, fontName: string, seen?: WeakSet<WeakKey>) => void;
|
package/package.json
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import React, { useContext, useState, useEffect } from 'react';
|
2
|
-
import { Schema, Plugin, BasePdf } from '@pdfme/common';
|
2
|
+
import { Schema, Plugin, BasePdf, getFallbackFontName } from '@pdfme/common';
|
3
3
|
import { theme, Button } from 'antd';
|
4
4
|
import { useDraggable } from '@dnd-kit/core';
|
5
5
|
import { CSS } from '@dnd-kit/utilities';
|
6
6
|
import Renderer from '../Renderer.js';
|
7
7
|
import { LEFT_SIDEBAR_WIDTH } from '../../constants.js';
|
8
|
-
import {
|
8
|
+
import { setFontNameRecursively } from '../../helper';
|
9
|
+
import { OptionsContext, PluginsRegistry } from '../../contexts.js';
|
9
10
|
import PluginIcon from './PluginIcon.js';
|
10
11
|
|
11
12
|
const Draggable = (props: {
|
@@ -16,7 +17,12 @@ const Draggable = (props: {
|
|
16
17
|
}) => {
|
17
18
|
const { scale, basePdf, plugin } = props;
|
18
19
|
const { token } = theme.useToken();
|
20
|
+
const options = useContext(OptionsContext);
|
19
21
|
const defaultSchema = plugin.propPanel.defaultSchema;
|
22
|
+
if (options.font) {
|
23
|
+
const fontName = getFallbackFontName(options.font);
|
24
|
+
setFontNameRecursively(defaultSchema, fontName);
|
25
|
+
}
|
20
26
|
const draggable = useDraggable({ id: defaultSchema.type, data: defaultSchema });
|
21
27
|
const { listeners, setNodeRef, attributes, transform, isDragging } = draggable;
|
22
28
|
const style = { transform: CSS.Translate.toString(transform) };
|
package/src/helper.ts
CHANGED
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
SchemaForUI,
|
11
11
|
Size,
|
12
12
|
isBlankPdf,
|
13
|
-
PluginRegistry
|
13
|
+
PluginRegistry,
|
14
14
|
} from '@pdfme/common';
|
15
15
|
import { pdf2size } from '@pdfme/converter';
|
16
16
|
import { DEFAULT_MAX_ZOOM, RULER_HEIGHT } from './constants.js';
|
@@ -516,3 +516,20 @@ export const useMaxZoom = () => {
|
|
516
516
|
|
517
517
|
return options.maxZoom ? options.maxZoom / 100 : DEFAULT_MAX_ZOOM;
|
518
518
|
};
|
519
|
+
|
520
|
+
export const setFontNameRecursively = (
|
521
|
+
obj: Record<string, unknown>,
|
522
|
+
fontName: string,
|
523
|
+
seen = new WeakSet(),
|
524
|
+
): void => {
|
525
|
+
if (!obj || typeof obj !== 'object' || seen.has(obj)) return;
|
526
|
+
seen.add(obj);
|
527
|
+
|
528
|
+
for (const key in obj) {
|
529
|
+
if (key === 'fontName' && Object.prototype.hasOwnProperty.call(obj, key) && obj[key] === undefined) {
|
530
|
+
obj[key] = fontName;
|
531
|
+
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
532
|
+
setFontNameRecursively(obj[key] as Record<string, unknown>, fontName, seen);
|
533
|
+
}
|
534
|
+
}
|
535
|
+
};
|