@mittwald/flow-remote-react-components 1.6.1 → 1.6.2

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.
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  /* */
3
3
  import { version } from "../version.mjs";
4
- import { createElement } from "react";
4
+ import { createElement, useLayoutEffect, useRef } from "react";
5
5
  import { useControlledRemoteValueProps } from "@mittwald/flow-react-components/flr-universal";
6
6
  import { FlowRemoteElement } from "@mittwald/flow-remote-elements";
7
7
  import { createRemoteComponent } from "@mittwald/remote-dom-react";
@@ -14,14 +14,45 @@ var controlledComponentNames = [
14
14
  "flr-text-field",
15
15
  "flr-text-area"
16
16
  ];
17
+ /**
18
+ * One function per event prop for the element's lifetime, calling the handler
19
+ * of the latest render — as the Vue binding's wrapper does.
20
+ *
21
+ * Remote-dom re-registers a listener whose identity changed, and removing the
22
+ * element's last listener of an event releases the `dispatch` the host holds.
23
+ * An inline handler did that on every render, so a host event fired while a
24
+ * remote render was in flight called a released function and was lost — the
25
+ * last keystroke of a date field, for one.
26
+ */
27
+ var useStableEventHandlers = (props, eventPropNames) => {
28
+ const latestProps = useRef(props);
29
+ useLayoutEffect(() => {
30
+ latestProps.current = props;
31
+ });
32
+ const stableHandlers = useRef(null);
33
+ stableHandlers.current ??= /* @__PURE__ */ new Map();
34
+ const result = { ...props };
35
+ for (const name of eventPropNames) {
36
+ if (typeof props[name] !== "function") continue;
37
+ let handler = stableHandlers.current.get(name);
38
+ if (!handler) {
39
+ handler = (...args) => latestProps.current[name]?.(...args);
40
+ stableHandlers.current.set(name, handler);
41
+ }
42
+ result[name] = handler;
43
+ }
44
+ return result;
45
+ };
17
46
  var createRemoteComponent$1 = (name, element, options) => {
18
47
  const RemoteComponent = createRemoteComponent(name, element, options);
48
+ const eventPropNames = Object.keys(options?.eventProps ?? {});
49
+ const isControlledComponent = controlledComponentNames.includes(name);
19
50
  return (props) => {
20
- const isControlledComponent = controlledComponentNames.includes(name);
51
+ const controlledProps = isControlledComponent ? useControlledRemoteValueProps(props) : props;
21
52
  return createElement(RemoteComponent, {
22
53
  [FlowRemoteElement.initializationPropertyName]: true,
23
54
  [FlowRemoteElement.versionPropertyName]: version,
24
- ...isControlledComponent ? useControlledRemoteValueProps(props) : props
55
+ ...useStableEventHandlers(controlledProps, eventPropNames)
25
56
  });
26
57
  };
27
58
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createRemoteComponent.mjs","names":["createRemoteComponent","libCreateRemoteComponent"],"sources":["../../../src/lib/createRemoteComponent.ts"],"sourcesContent":["import { version } from \"@/version\";\nimport { useControlledRemoteValueProps } from \"@mittwald/flow-react-components/flr-universal\";\nimport { FlowRemoteElement } from \"@mittwald/flow-remote-elements\";\nimport { createRemoteComponent as libCreateRemoteComponent } from \"@mittwald/remote-dom-react\";\nimport { createElement } from \"react\";\n\nconst controlledComponentNames: (keyof HTMLElementTagNameMap)[] = [\n \"flr-markdown-editor\",\n \"flr-number-field\",\n \"flr-password-creation-field\",\n \"flr-search-field\",\n \"flr-text-field\",\n \"flr-text-area\",\n];\n\nexport const createRemoteComponent: typeof libCreateRemoteComponent = (\n name,\n element,\n options,\n) => {\n const RemoteComponent = libCreateRemoteComponent(name, element, options);\n return (props) => {\n const isControlledComponent = controlledComponentNames.includes(\n name as keyof HTMLElementTagNameMap,\n );\n\n return createElement(RemoteComponent, {\n [FlowRemoteElement.initializationPropertyName]: true,\n [FlowRemoteElement.versionPropertyName]: version,\n ...(isControlledComponent ? useControlledRemoteValueProps(props) : props),\n });\n };\n};\n"],"mappings":";;;;;;;;AAMA,IAAM,2BAA4D;CAChE;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAaA,2BACX,MACA,SACA,YACG;CACH,MAAM,kBAAkBC,sBAAyB,MAAM,SAAS,OAAO;CACvE,QAAQ,UAAU;EAChB,MAAM,wBAAwB,yBAAyB,SACrD,IACF;EAEA,OAAO,cAAc,iBAAiB;IACnC,kBAAkB,6BAA6B;IAC/C,kBAAkB,sBAAsB;GACzC,GAAI,wBAAwB,8BAA8B,KAAK,IAAI;EACrE,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"createRemoteComponent.mjs","names":["createRemoteComponent","libCreateRemoteComponent"],"sources":["../../../src/lib/createRemoteComponent.ts"],"sourcesContent":["import { version } from \"@/version\";\nimport { useControlledRemoteValueProps } from \"@mittwald/flow-react-components/flr-universal\";\nimport { FlowRemoteElement } from \"@mittwald/flow-remote-elements\";\nimport { createRemoteComponent as libCreateRemoteComponent } from \"@mittwald/remote-dom-react\";\nimport { createElement, useLayoutEffect, useRef } from \"react\";\n\nconst controlledComponentNames: (keyof HTMLElementTagNameMap)[] = [\n \"flr-markdown-editor\",\n \"flr-number-field\",\n \"flr-password-creation-field\",\n \"flr-search-field\",\n \"flr-text-field\",\n \"flr-text-area\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype AnyFunction = (...args: any[]) => unknown;\n\n/**\n * One function per event prop for the element's lifetime, calling the handler\n * of the latest render — as the Vue binding's wrapper does.\n *\n * Remote-dom re-registers a listener whose identity changed, and removing the\n * element's last listener of an event releases the `dispatch` the host holds.\n * An inline handler did that on every render, so a host event fired while a\n * remote render was in flight called a released function and was lost — the\n * last keystroke of a date field, for one.\n */\nconst useStableEventHandlers = <P extends Record<string, unknown>>(\n props: P,\n eventPropNames: readonly string[],\n): P => {\n const latestProps = useRef(props);\n useLayoutEffect(() => {\n latestProps.current = props;\n });\n\n const stableHandlers = useRef<Map<string, AnyFunction>>(null);\n stableHandlers.current ??= new Map();\n\n const result: Record<string, unknown> = { ...props };\n for (const name of eventPropNames) {\n if (typeof props[name] !== \"function\") {\n continue;\n }\n let handler = stableHandlers.current.get(name);\n if (!handler) {\n handler = (...args) =>\n (latestProps.current[name] as AnyFunction | undefined)?.(...args);\n stableHandlers.current.set(name, handler);\n }\n result[name] = handler;\n }\n return result as P;\n};\n\nexport const createRemoteComponent: typeof libCreateRemoteComponent = (\n name,\n element,\n options,\n) => {\n const RemoteComponent = libCreateRemoteComponent(name, element, options);\n const eventPropNames = Object.keys(options?.eventProps ?? {});\n const isControlledComponent = controlledComponentNames.includes(\n name as keyof HTMLElementTagNameMap,\n );\n\n return (props) => {\n const controlledProps = isControlledComponent\n ? useControlledRemoteValueProps(props)\n : props;\n\n return createElement(RemoteComponent, {\n [FlowRemoteElement.initializationPropertyName]: true,\n [FlowRemoteElement.versionPropertyName]: version,\n ...useStableEventHandlers(controlledProps, eventPropNames),\n });\n };\n};\n"],"mappings":";;;;;;;;AAMA,IAAM,2BAA4D;CAChE;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;AAeA,IAAM,0BACJ,OACA,mBACM;CACN,MAAM,cAAc,OAAO,KAAK;CAChC,sBAAsB;EACpB,YAAY,UAAU;CACxB,CAAC;CAED,MAAM,iBAAiB,OAAiC,IAAI;CAC5D,eAAe,4BAAY,IAAI,IAAI;CAEnC,MAAM,SAAkC,EAAE,GAAG,MAAM;CACnD,KAAK,MAAM,QAAQ,gBAAgB;EACjC,IAAI,OAAO,MAAM,UAAU,YACzB;EAEF,IAAI,UAAU,eAAe,QAAQ,IAAI,IAAI;EAC7C,IAAI,CAAC,SAAS;GACZ,WAAW,GAAG,SACX,YAAY,QAAQ,KAAK,GAA+B,GAAG,IAAI;GAClE,eAAe,QAAQ,IAAI,MAAM,OAAO;EAC1C;EACA,OAAO,QAAQ;CACjB;CACA,OAAO;AACT;AAEA,IAAaA,2BACX,MACA,SACA,YACG;CACH,MAAM,kBAAkBC,sBAAyB,MAAM,SAAS,OAAO;CACvE,MAAM,iBAAiB,OAAO,KAAK,SAAS,cAAc,CAAC,CAAC;CAC5D,MAAM,wBAAwB,yBAAyB,SACrD,IACF;CAEA,QAAQ,UAAU;EAChB,MAAM,kBAAkB,wBACpB,8BAA8B,KAAK,IACnC;EAEJ,OAAO,cAAc,iBAAiB;IACnC,kBAAkB,6BAA6B;IAC/C,kBAAkB,sBAAsB;GACzC,GAAG,uBAAuB,iBAAiB,cAAc;EAC3D,CAAC;CACH;AACF"}
@@ -3,7 +3,7 @@
3
3
  import { Version } from "@mittwald/flow-remote-core";
4
4
  // src/version.ts
5
5
  var communicationVersion = Version.v6;
6
- var packageVersion = "1.6.1";
6
+ var packageVersion = "1.6.2";
7
7
  var version = communicationVersion;
8
8
  export { communicationVersion, packageVersion, version };
9
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/flow-remote-react-components",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "type": "module",
5
5
  "description": "React components that can be used in a remote environment",
6
6
  "homepage": "https://flow.mittwald.de",
@@ -53,19 +53,19 @@
53
53
  "test:visual:update": "vitest run --project=visual --browser.headless --update=true"
54
54
  },
55
55
  "dependencies": {
56
- "@mittwald/flow-react-components": "1.6.1",
57
- "@mittwald/flow-remote-core": "1.6.1",
58
- "@mittwald/flow-remote-elements": "1.6.1",
56
+ "@mittwald/flow-react-components": "1.6.2",
57
+ "@mittwald/flow-remote-core": "1.6.2",
58
+ "@mittwald/flow-remote-elements": "1.6.2",
59
59
  "@mittwald/remote-dom-react": "1.2.2-mittwald.10",
60
60
  "@types/react": "^19.2",
61
61
  "react-error-boundary": "^6.1.3"
62
62
  },
63
63
  "devDependencies": {
64
64
  "@internationalized/date": "^3.12.3",
65
- "@mittwald/ext-bridge": "1.6.1",
66
- "@mittwald/flow-core": "1.6.1",
67
- "@mittwald/flow-remote-react-renderer": "1.6.1",
68
- "@mittwald/typescript-config": "1.6.1",
65
+ "@mittwald/ext-bridge": "1.6.2",
66
+ "@mittwald/flow-core": "1.6.2",
67
+ "@mittwald/flow-remote-react-renderer": "1.6.2",
68
+ "@mittwald/typescript-config": "1.6.2",
69
69
  "@quilted/threads": "^3.3.1",
70
70
  "@tabler/icons-react": "^3.44.0",
71
71
  "@types/node": "^25.9.3",
@@ -91,7 +91,7 @@
91
91
  },
92
92
  "peerDependencies": {
93
93
  "@internationalized/date": "^3.12.2",
94
- "@mittwald/ext-bridge": "1.6.1",
94
+ "@mittwald/ext-bridge": "1.6.2",
95
95
  "react": "^19.2.0",
96
96
  "react-hook-form": "^7.65.0"
97
97
  },
@@ -106,5 +106,5 @@
106
106
  "optional": true
107
107
  }
108
108
  },
109
- "gitHead": "94ef5d178ad86aa0c2d98e07b37944c9f8658a29"
109
+ "gitHead": "b99354188b0005eaacaf2044ed7ee85d37f3cb91"
110
110
  }