Skip to content

Commit 2d797d6

Browse files
committed
feat: implement script component (viewer)
Related to #1102
1 parent 8b378d2 commit 2d797d6

File tree

11 files changed

+237
-54
lines changed

11 files changed

+237
-54
lines changed

package-lock.json

Lines changed: 33 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/form-js-viewer/assets/form-js-base.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,10 @@
12031203
margin-right: 4px;
12041204
}
12051205

1206+
.fjs-container .fjs-sandbox-iframe-container {
1207+
display: none;
1208+
}
1209+
12061210
/**
12071211
* Flatpickr style adjustments
12081212
*/

packages/form-js-viewer/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@carbon/grid": "^11.11.0",
49+
"@jetbrains/websandbox": "^1.0.10",
4950
"big.js": "^6.2.1",
5051
"classnames": "^2.3.1",
5152
"didi": "^10.2.2",
@@ -57,7 +58,8 @@
5758
"lodash": "^4.5.0",
5859
"marked": "^12.0.1",
5960
"min-dash": "^4.2.1",
60-
"preact": "^10.5.14"
61+
"preact": "^10.5.14",
62+
"uuid": "^9.0.1"
6163
},
6264
"sideEffects": [
6365
"*.css"

packages/form-js-viewer/rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default [
5858
'flatpickr',
5959
'marked',
6060
'@carbon/grid',
61+
'@jetbrains/websandbox',
6162
'feelers',
6263
'dompurify'
6364
],

packages/form-js-viewer/src/Form.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,42 +446,44 @@ export class Form {
446446
const pathRegistry = this.get('pathRegistry');
447447
const formData = this._getState().data;
448448

449-
function collectSubmitDataRecursively(submitData, formField, indexes) {
450-
const { disabled, type } = formField;
449+
function collectSubmitDataRecursively(submitData, field, indexes) {
450+
const { disabled, type } = field;
451451
const { config: fieldConfig } = formFields.get(type);
452452

453453
// (1) Process keyed fields
454-
if (!disabled && fieldConfig.keyed) {
455-
const valuePath = pathRegistry.getValuePath(formField, { indexes });
454+
const isSubmittedKeyedField = fieldConfig.keyed && !disabled && !(fieldConfig.allowDoNotSubmit && field.doNotSubmit);
455+
456+
if (isSubmittedKeyedField) {
457+
const valuePath = pathRegistry.getValuePath(field, { indexes });
456458
const value = get(formData, valuePath);
457459
set(submitData, valuePath, value);
458460
}
459461

460462
// (2) Process parents
461-
if (!Array.isArray(formField.components)) {
463+
if (!Array.isArray(field.components)) {
462464
return;
463465
}
464466

465467
// (3a) Recurse repeatable parents both across the indexes of repetition and the children
466-
if (fieldConfig.repeatable && formField.isRepeating) {
468+
if (fieldConfig.repeatable && field.isRepeating) {
467469

468-
const valueData = get(formData, pathRegistry.getValuePath(formField, { indexes }));
470+
const valueData = get(formData, pathRegistry.getValuePath(field, { indexes }));
469471

470472
if (!Array.isArray(valueData)) {
471473
return;
472474
}
473475

474476
valueData.forEach((_, index) => {
475-
formField.components.forEach((component) => {
476-
collectSubmitDataRecursively(submitData, component, { ...indexes, [formField.id]: index });
477+
field.components.forEach((component) => {
478+
collectSubmitDataRecursively(submitData, component, { ...indexes, [field.id]: index });
477479
});
478480
});
479481

480482
return;
481483
}
482484

483485
// (3b) Recurse non-repeatable parents only across the children
484-
formField.components.forEach((component) => collectSubmitDataRecursively(submitData, component, indexes));
486+
field.components.forEach((component) => collectSubmitDataRecursively(submitData, component, indexes));
485487
}
486488

487489
const workingSubmitData = {};

packages/form-js-viewer/src/render/components/form-fields/ExpressionField.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export function ExpressionField(props) {
4141
ExpressionField.config = {
4242
type,
4343
label: 'Expression',
44-
group: 'basic-input',
44+
group: 'advanced',
4545
keyed: true,
4646
emptyValue: null,
47+
allowDoNotSubmit: true,
4748
escapeGridRender: true,
4849
create: (options = {}) => ({
4950
computeOn: 'change',

0 commit comments

Comments
 (0)