diff --git a/package.json b/package.json index 13df0c1..f33025f 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "Budibase-Signature-Plugin", - "version": "1.2.3", + "version": "1.2.4", "description": "A plugin that allows signatures to be created and saved in budibase", "license": "MIT", "svelte": "index.js", "module": "dist/plugin.min.js", + "author": "Lewis McRobbie", "scripts": { "build": "rollup -c", "watch": "rollup -cw" diff --git a/src/Canvas.svelte b/src/Canvas.svelte index 2789b91..2164736 100644 --- a/src/Canvas.svelte +++ b/src/Canvas.svelte @@ -20,6 +20,7 @@ export let borderOutline = "none" export let borderColor = "#000000" export let borderWidth = "1px" + export let inBuilder = false let eraseSignatureModal let canvas @@ -30,12 +31,15 @@ let t, l onMount(() => { - context = canvas.getContext('2d') - context.lineWidth = penWidth; - context.lineJoin = "round"; - context.lineCap = "round"; - - handleSize() + if (!inBuilder){ + context = canvas.getContext('2d') + context.lineWidth = penWidth; + context.lineJoin = "round"; + context.lineCap = "round"; + + handleSize(); + saveSignature(true); + } }) $: if(context) { @@ -43,90 +47,114 @@ } const handleStart = (({ offsetX: x, offsetY: y }) => { - if(color === background) { - context.clearRect(0, 0, width, height) - } else { - isDrawing = true - start = { x, y } - } + if (!inBuilder){ + if(color === background) { + context.clearRect(0, 0, width, height) + } else { + isDrawing = true + start = { x, y } + } + } }) const handleEnd = () => { - isDrawing = false; - saveSignature(); + if (!inBuilder){ + isDrawing = false; + saveSignature(false); + } } const handleMove = (({ offsetX: x1, offsetY: y1 }) => { - if(!isDrawing) return - - const { x, y } = start - context.beginPath() - context.moveTo(x, y) - context.lineTo(x1, y1) - context.closePath() - context.stroke() - - start = { x: x1, y: y1 } + if (!inBuilder){ + if(!isDrawing) return + + const { x, y } = start + context.beginPath() + context.moveTo(x, y) + context.lineTo(x1, y1) + context.closePath() + context.stroke() + + start = { x: x1, y: y1 } + } }) const handleSize = () => { - const { top, left } = canvas.getBoundingClientRect() - t = top - l = left + const { top, left } = canvas.getBoundingClientRect() + t = top + l = left } function clearCanvas(){ - const context = canvas.getContext('2d'); - context.clearRect(0, 0, canvas.width, canvas.height); - saveSignature(); + if (!inBuilder){ + const context = canvas.getContext('2d'); + context.clearRect(0, 0, canvas.width, canvas.height); + saveSignature(false); + } } function fillCanvasBackgroundWithColor(color) { - if (saveBackgroundColour){ - const context = canvas.getContext('2d'); - context.save(); - context.globalCompositeOperation = 'destination-over'; - context.fillStyle = color; - context.fillRect(0, 0, canvas.width, canvas.height); - context.restore(); + if (!inBuilder){ + if (saveBackgroundColour){ + const context = canvas.getContext('2d'); + context.save(); + context.globalCompositeOperation = 'destination-over'; + context.fillStyle = color; + context.fillRect(0, 0, canvas.width, canvas.height); + context.restore(); + } } } - function saveSignature(){ - fillCanvasBackgroundWithColor(background); - let img = canvas.toDataURL("image/png"); - setSignatureValue(img); + function saveSignature(inital){ + if (!inBuilder){ + fillCanvasBackgroundWithColor(background); + let img = canvas.toDataURL("image/png"); + setSignatureValue(img, inital); + } } - {#if showClearSignatureButton} -
- {#if showButtonIcon} - - {:else} - - {/if} - - - {modalBody} - - +
+ {#if showButtonIcon} + {#if !inBuilder} + + {:else} + + {/if} + {:else} + {#if !inBuilder} + + {:else} + + {/if} + {/if} + {#if !inBuilder} + + + {modalBody} + + + {/if}
{/if} -
{#if !canBeDisplayed} - +
Signature field error @@ -150,6 +177,7 @@ $: formField = formApi?.registerField( {borderOutline} {borderColor} {borderWidth} + {inBuilder} >