Skip to main content

DIQWidgetBridge

Last updated 7/05/2026

Embed the

DimensionIQWidget
and integrate it into your application using a callback-driven SDK.

Overview

DIQWidgetBridge
lets you:

  • Embed the widget in your app
  • Send commands to control it
  • Handle user actions via callbacks
  • Sync widget data with your backend

Integration is primarily done through callbacks.

Quick Start

TypeScript
import { DIQWidgetBridge } from './DIQWidgetBridge';

const bridge = new DIQWidgetBridge({
container: document.getElementById('widget-container')!,
iframeURL: 'https://www.dimensioniq.com/control/{build}/iframe-widget/src/widget.php?key=DIQ-DEMO-0000-0000',

onReady: () => {
bridge.sendCommand('loadProject', myProject);
},

callbacks: {
onDimensionsNew: (dimensions: Array<DIQ_Dimension>, onResponse: (result: DIQ_Result) => void) => {
saveToDB(dimensions).then(() => onResponse({ ok: true }));
},
},
});

How Integration Works

There are only two things you need to wire up:

1. Send Commands

You control the widget using:

TypeScript
bridge.sendCommand('action', ...args);

Typical example:

TypeScript
bridge.sendCommand('loadProject', projectPayLoad);

2. Handle Callbacks

The widget notifies your app through callbacks.

TypeScript
callbacks: {
onDimensionsNew: (dimensions: Array<DIQ_Dimension>, onResponse: (result: DIQ_Result) => void) => {
saveToDB(dimensions).then(() => onResponse({ ok: true }));
}
}

Responding to Events

onResponse()
must always be called once the host application has finished processing the event.

TypeScript
onDimensionsNew: (dimensions: Array<DIQ_Dimension>, onResponse: (result: DIQ_Result) => void) => {
saveToDB(dimensions)
.then(() => onResponse({ ok: true }))
.catch(() => onResponse({ ok: false }));
}

Typical Integration Flow

  1. Create the bridge.
  2. Wait for
    onReady
    .
  3. Handle updates via callbacks.
  4. Persist data to your backend.
  5. Clean up when done.

Lifecycle Management

Always clean up:

TypeScript
bridge.destroy();

Common Pattern: Persisting Data

TypeScript
callbacks: {
onDimensionsNew: (dimensions: Array<DIQ_Dimension>, onResponse: (result: DIQ_Result) => void) => {
saveToDB(dims)
.then(() => onResponse({ ok: true }))
.catch(() => onResponse({ ok: false }));
},

onDimensionUpdate: (dimension: DIQ_Dimension, onResponse: (result: DIQ_Result) => void) => {
updateInDB(dim)
.then(() => onResponse({ ok: true }))
.catch(() => onResponse({ ok: false }));
}
}

Best Practices

  • Initialize your project inside
    onReady
  • Treat callbacks as your source of truth
  • Always call
    onResponse()
    when required
  • Keep backend logic inside callbacks
  • Call
    destroy()
    on teardown

API Reference

Constructor

TypeScript
new DIQWidgetBridge(options: DIQWidgetBridgeOptions)

DIQWidgetBridgeOptions

Required
FieldTypeDescription
containerHTMLElementElement that will host the widget. Must have a defined size.
iframeURLstringFull widget URL including
?key=YOUR_KEY
.

Optional
FieldTypeDescription
callbacksPartial<Callbacks>Event handlers from the widget.
onReady() => voidCalled once when the widget is ready.
onTimeout() => voidCalled if initialization times out.
onError(err:Error) => voidCalled if the widget fails to load.
readyTimeoutnumberWidget initialization timeout in milliseconds.
verbosebooleanEnables debug logging.
theme
DIQTheme
Theme used to customize the widget appearance. Sent to the widget once connected. Omitted values fall back to the DimensionIQ defaults.
config
DIQWidgetConfig
Behavioral configuration for the widget. Sent to the widget once connected.

Methods

sendCommand
TypeScript
sendCommand(action: string, ...args: any[]): void

Sends a command to the widget.

Examples

TypeScript
bridge.sendCommand('loadProject', projectPayload);
bridge.sendCommand('setDimensionMode', 'length');
bridge.sendCommand('setMeasurementSystem', 'imperial');
setCallbacks
TypeScript
setCallbacks(callbacks: Callbacks): void

Replaces all callbacks after initialization.

destroy
TypeScript
destroy(): void

Removes the widget and cleans up resources.

Error Handling

  • onTimeout
    - widget didn't initialize in time
  • onError
    - iframe failed to load
  • onResponse({ ok: false })
    - operation failed

Lifecycle Summary

StageAction
Initialize
new DIQWidgetBridge()
Ready
onReady
fires
Operate
sendCommand
+ callbacks
Cleanup
destroy()