-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Niklas Kiefer
committed
Nov 9, 2023
1 parent
2c55d53
commit 27eb42d
Showing
15 changed files
with
265 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/form-js-editor/src/features/properties-panel/entries/IFrameHeightEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import HeightEntry from './HeightEntry'; | ||
|
||
export default function IFrameHeightEntry(props) { | ||
return [ | ||
...HeightEntry({ | ||
...props, | ||
description: 'Height of the container in pixels.', | ||
isDefaultVisible: (field) => field.type === 'iframe' | ||
}) | ||
]; | ||
} |
74 changes: 74 additions & 0 deletions
74
packages/form-js-editor/src/features/properties-panel/entries/IFrameUrlEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { get } from 'min-dash'; | ||
|
||
import { useService, useVariables } from '../hooks'; | ||
|
||
import { FeelTemplatingEntry, isFeelEntryEdited } from '@bpmn-io/properties-panel'; | ||
|
||
export default function IFrameUrlEntry(props) { | ||
const { | ||
editField, | ||
field | ||
} = props; | ||
|
||
const entries = []; | ||
entries.push({ | ||
id: 'url', | ||
component: Url, | ||
editField: editField, | ||
field: field, | ||
isEdited: isFeelEntryEdited, | ||
isDefaultVisible: (field) => field.type === 'iframe' | ||
}); | ||
|
||
return entries; | ||
} | ||
|
||
function Url(props) { | ||
const { | ||
editField, | ||
field, | ||
id | ||
} = props; | ||
|
||
const debounce = useService('debounce'); | ||
|
||
const variables = useVariables().map(name => ({ name })); | ||
|
||
const path = [ 'url' ]; | ||
|
||
const getValue = () => { | ||
return get(field, path, ''); | ||
}; | ||
|
||
const setValue = (value) => { | ||
return editField(field, path, value); | ||
}; | ||
|
||
return FeelTemplatingEntry({ | ||
debounce, | ||
element: field, | ||
feel: 'optional', | ||
getValue, | ||
id, | ||
label: 'URL', | ||
setValue, | ||
singleLine: true, | ||
tooltip: getTooltip(), | ||
variables | ||
}); | ||
} | ||
|
||
// helper ////////////////////// | ||
|
||
function getTooltip() { | ||
return ( | ||
<> | ||
<p> | ||
Enter a URL to an external source or populate it dynamically via a template or a FEEL expression (e.g., to pass a value from the variable). | ||
</p> | ||
<p> | ||
However, not all external sources can be displayed. Read more about it in the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options">X-FRAME-OPTIONS documentation</a>. | ||
</p> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/form-js-editor/src/render/components/editor-form-fields/EditorIFrame.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { | ||
IFrame | ||
} from '@bpmn-io/form-js-viewer'; | ||
|
||
|
||
export default function EditorIFrame(props) { | ||
const { field } = props; | ||
|
||
// remove url to display placeholder | ||
return <IFrame { ...{ ...props, field: { ...field, url: null } } } />; | ||
|
||
} | ||
|
||
EditorIFrame.config = IFrame.config; |
2 changes: 2 additions & 0 deletions
2
packages/form-js-editor/src/render/components/editor-form-fields/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import EditorIFrame from './EditorIFrame'; | ||
import EditorText from './EditorText'; | ||
|
||
export const editorFormFields = [ | ||
EditorIFrame, | ||
EditorText | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/form-js-viewer/src/render/components/form-fields/IFrame.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { useContext, useMemo } from 'preact/hooks'; | ||
|
||
import { FormContext } from '../../context'; | ||
|
||
import { useSingleLineTemplateEvaluation } from '../../hooks'; | ||
import { sanitizeIFrameSource } from '../Sanitizer'; | ||
|
||
import Label from '../Label'; | ||
|
||
import { | ||
formFieldClasses, | ||
prefixId | ||
} from '../Util'; | ||
|
||
import { iconsByType } from '../icons'; | ||
|
||
const type = 'iframe'; | ||
|
||
const DEFAULT_HEIGHT = 300; | ||
|
||
export default function IFrame(props) { | ||
const { | ||
field, | ||
disabled, | ||
readonly | ||
} = props; | ||
|
||
const { | ||
height = DEFAULT_HEIGHT, | ||
id, | ||
label, | ||
url | ||
} = field; | ||
|
||
const evaluatedUrl = useSingleLineTemplateEvaluation(url, { debug: true }); | ||
|
||
const safeUrl = useMemo(() => sanitizeIFrameSource(evaluatedUrl), [ evaluatedUrl ]); | ||
|
||
const evaluatedLabel = useSingleLineTemplateEvaluation(label, { debug: true }); | ||
|
||
const { formId } = useContext(FormContext); | ||
|
||
return <div class={ formFieldClasses(type, { disabled, readonly }) }> | ||
<Label id={ prefixId(id, formId) } label={ evaluatedLabel } /> | ||
{ | ||
safeUrl && | ||
<iframe | ||
src={ safeUrl } | ||
title={ evaluatedLabel } | ||
height={ height } | ||
class="fjs-iframe" | ||
id={ prefixId(id, formId) } /> | ||
} | ||
{ | ||
!safeUrl && <IFramePlaceholder /> | ||
} | ||
</div>; | ||
} | ||
|
||
function IFramePlaceholder() { | ||
const Icon = iconsByType(type); | ||
|
||
return <div class="fjs-iframe-placeholder"> | ||
<p class="fjs-iframe-placeholder-text"><Icon width="32" height="24" />iFrame</p> | ||
</div>; | ||
} | ||
|
||
IFrame.config = { | ||
type, | ||
keyed: false, | ||
label: 'iFrame', | ||
group: 'container', | ||
create: (options = {}) => ({ | ||
...options | ||
}) | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.