-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5028 from open-formulieren/feature/sdk-76-use-esm…
…-bundle Opt-in to ESM bundle of SDK
- Loading branch information
Showing
6 changed files
with
82 additions
and
11 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
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,6 +1,6 @@ | ||
{% load i18n %}{% if enabled %} | ||
<div class="info-bar"> | ||
<span>{% trans "Javascript SDK used" %}</span> | ||
<code>{{ sdk_js_url }}</code> | ||
<code>{{ sdk_umd_url }}</code> | ||
</div> | ||
{% endif %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// NOTE - this file must be in the static folder and loaded as type="module", since | ||
// it's intended for modern browsers only and must be ignored by browsers that don't | ||
// natively support modules. | ||
|
||
/** | ||
* Given a form node on the page, extract the options from the data-* attributes and | ||
* initialize it. | ||
* @param {HTMLDivElement} node The root node for the SDK where the form must be | ||
* rendered. It must have the expected data attributes. | ||
* @return {Void} | ||
*/ | ||
const initializeSDK = async node => { | ||
const { | ||
sdkModule, | ||
formId, | ||
baseUrl, | ||
basePath, | ||
cspNonce, | ||
sentryDsn = '', | ||
sentryEnv = '', | ||
} = node.dataset; | ||
const {OpenForm} = await import(sdkModule); | ||
|
||
// initialize the SDK | ||
const options = { | ||
baseUrl, | ||
formId, | ||
basePath, | ||
CSPNonce: cspNonce, | ||
}; | ||
if (sentryDsn) options.sentryDSN = sentryDsn; | ||
if (sentryEnv) options.sentryEnv = sentryEnv; | ||
const form = new OpenForm(node, options); | ||
form.init(); | ||
}; | ||
|
||
const sdkNodes = document.querySelectorAll('.open-forms-sdk-root'); | ||
sdkNodes.forEach(node => initializeSDK(node)); |
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