@samline/forms 2.3.4 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,10 +42,10 @@ Requires Node 20+ when bundling. Runtime target is ES2020.
42
42
  Use the browser build when you do not have a bundler and need to run the package directly in HTML, Shopify, WordPress, or any traditional template.
43
43
 
44
44
  ```html
45
- <script src="https://unpkg.com/@samline/forms@2.3.4/dist/browser/global.global.js"></script>
45
+ <script src="https://unpkg.com/@samline/forms@2.4.0/dist/browser/global.global.js"></script>
46
46
  ```
47
47
 
48
- > Pin the version in production. Replace `2.3.4` with the version you ship.
48
+ > Pin the version in production. Replace `2.4.0` with the version you ship.
49
49
 
50
50
  The browser bundle exposes a single global: `window.Forms`.
51
51
 
@@ -55,7 +55,7 @@ The browser bundle exposes a single global: `window.Forms`.
55
55
  <button type="submit">Send</button>
56
56
  </form>
57
57
 
58
- <script src="https://unpkg.com/@samline/forms@2.3.4/dist/browser/global.global.js"></script>
58
+ <script src="https://unpkg.com/@samline/forms@2.4.0/dist/browser/global.global.js"></script>
59
59
  <script>
60
60
  const contactForm = window.Forms.newForm({ id: 'contact-form' })
61
61
 
@@ -4846,6 +4846,11 @@ var Forms = (() => {
4846
4846
  const candidate = event;
4847
4847
  return typeof candidate.inputType === "string" ? candidate.inputType : void 0;
4848
4848
  };
4849
+ var buildAutoInterpretedOptions = (formatOptions) => ({
4850
+ ...formatOptions ?? {},
4851
+ interpretInputAs: "auto"
4852
+ });
4853
+ var shouldForceAutoInterpretation = (formatOptions) => formatOptions?.interpretInputAs === void 0;
4849
4854
  var buildHandler = (visible, mirror, formatFn, formatType, formatOptions) => {
4850
4855
  const handler = (event) => {
4851
4856
  if (!visible.isConnected || !mirror.isConnected) return;
@@ -4854,7 +4859,8 @@ var Forms = (() => {
4854
4859
  if (!isVisible && !isMirror) return;
4855
4860
  const rawInput = isMirror ? mirror.value : visible.value;
4856
4861
  const inputType = readInputType(event);
4857
- const { formatted, raw } = formatFn(rawInput, formatType, formatOptions);
4862
+ const sourceOptions = isMirror && shouldForceAutoInterpretation(formatOptions) ? buildAutoInterpretedOptions(formatOptions) : formatOptions;
4863
+ const { formatted, raw } = formatFn(rawInput, formatType, sourceOptions);
4858
4864
  if (!formatted && !raw) {
4859
4865
  visible.value = "";
4860
4866
  if (mirror.value !== "") mirror.value = "";
@@ -4939,7 +4945,8 @@ var Forms = (() => {
4939
4945
  entry.handler = handler;
4940
4946
  const initial = entry.visible.value;
4941
4947
  if (initial !== "") {
4942
- const { formatted, raw } = formatter.format(initial, formatType, formatOptions);
4948
+ const initialOptions = shouldForceAutoInterpretation(formatOptions) ? buildAutoInterpretedOptions(formatOptions) : formatOptions;
4949
+ const { formatted, raw } = formatter.format(initial, formatType, initialOptions);
4943
4950
  applyFormattedValue(entry.visible, entry.mirror, formatted, raw);
4944
4951
  } else if (entry.mirrorIsOwned && entry.mirror.value !== "") {
4945
4952
  entry.mirror.value = "";