Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,3 +2539,4 @@ gulp.task("externaltest", function (done) {
});
done();
});

97 changes: 53 additions & 44 deletions src/scripting_api/initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,57 +71,66 @@ function initSandbox(params) {
const appObjects = app._objects;

if (data.objects) {
const annotations = [];

for (const [name, objs] of Object.entries(data.objects)) {
annotations.length = 0;
let container = null;

for (const obj of objs) {
if (obj.type !== "") {
annotations.push(obj);
} else {
container = obj;
// Separate annotations and container
const annotations = objs.filter(obj => obj.type !== "");
const container = objs.find(obj => obj.type === "");

// Process each annotation (button, checkbox, etc.)
for (const obj of annotations) {
obj.send = send; // Assign the send function to each annotation
obj.globalEval = globalEval;
obj.doc = _document;
obj.fieldPath = name;
obj.appObjects = appObjects;

// Handle siblings (if any)
const otherFields = annotations.filter(x => x !== obj);
if (otherFields.length > 0) {
obj.siblings = otherFields.map(x => x.id);
}
}

let obj = container;
if (annotations.length > 0) {
obj = annotations[0];
obj.send = send;
}

obj.globalEval = globalEval;
obj.doc = _document;
obj.fieldPath = name;
obj.appObjects = appObjects;

const otherFields = annotations.slice(1);

let field;
switch (obj.type) {
case "radiobutton": {
field = new RadioButtonField(otherFields, obj);
break;
}
case "checkbox": {
field = new CheckboxField(otherFields, obj);
break;
// Create a Field instance based on the type
let field;
switch (obj.type) {
case "radiobutton":
field = new RadioButtonField(
otherFields.map(x => x.id),
obj
); // Pass sibling IDs
break;
case "checkbox":
field = new CheckboxField(
otherFields.map(x => x.id),
obj
); // Pass sibling IDs
break;
default:
field = new Field(obj);
}
default:
if (otherFields.length > 0) {
obj.siblings = otherFields.map(x => x.id);
}
field = new Field(obj);
}

const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };
doc._addField(name, _object);
for (const object of objs) {
appObjects[object.id] = _object;
// Wrap the field in a Proxy and add it to doc and appObjects
const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };
doc._addField(name, _object);
appObjects[obj.id] = _object;
}

// Handle the container (if it exists)
if (container) {
container.send = send;
container.globalEval = globalEval;
container.doc = _document;
container.fieldPath = name;
container.appObjects = appObjects;

// Create a Field instance for the container
const field = new Field(container);
const wrapped = new Proxy(field, proxyHandler);
const _object = { obj: field, wrapped };

// Add the container to doc and appObjects
doc._addField(name, _object);
appObjects[container.id] = _object;
}
}
Expand Down