@select-org/select-post-builder 1.3.0 → 1.3.1

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.
@@ -20613,8 +20613,7 @@ class SessionManager {
20613
20613
  placement: d,
20614
20614
  startTime: Date.now(),
20615
20615
  lastErrorType: null,
20616
- hasUserFocused: !1,
20617
- focusTime: null,
20616
+ focusSources: /* @__PURE__ */ new Set(),
20618
20617
  contentCreatedFired: !1,
20619
20618
  featureUsageCounts: /* @__PURE__ */ new Map()
20620
20619
  }), p;
@@ -20625,9 +20624,9 @@ class SessionManager {
20625
20624
  deleteSession(n) {
20626
20625
  this.sessions.delete(n);
20627
20626
  }
20628
- markFocused(n) {
20629
- const d = this.getSession(n);
20630
- d && !d.hasUserFocused && (d.hasUserFocused = !0, d.focusTime = Date.now());
20627
+ markFocused(n, d) {
20628
+ const p = this.getSession(n);
20629
+ return !p || p.focusSources.has(d) ? !1 : (p.focusSources.add(d), !0);
20631
20630
  }
20632
20631
  setLastError(n, d) {
20633
20632
  const p = this.getSession(n);
@@ -21904,13 +21903,14 @@ const analyticsStore = createStore((u, n) => ({
21904
21903
  }
21905
21904
  );
21906
21905
  },
21907
- trackEditorFocus: (d) => {
21908
- const { sessionManager: p, trackEvent: m } = n();
21909
- p.markFocused(d);
21910
- const g = p.getSession(d), y = g?.focusTime ? g.focusTime - g.startTime : null;
21911
- m(d, ANALYTICS_EVENTS.EDITOR.FOCUSED, {
21906
+ trackEditorFocus: (d, p) => {
21907
+ const { sessionManager: m, trackEvent: g } = n();
21908
+ if (!m.markFocused(d, p)) return;
21909
+ const y = m.getSession(d);
21910
+ g(d, ANALYTICS_EVENTS.EDITOR.FOCUSED, {
21912
21911
  surface: "editor",
21913
- time_to_focus_ms: y || void 0
21912
+ focus_source: p,
21913
+ time_to_focus_ms: y ? Date.now() - y.startTime : void 0
21914
21914
  });
21915
21915
  },
21916
21916
  trackTabSwitch: (d, p, m) => {
@@ -22003,7 +22003,7 @@ function useAnalyticsTracking() {
22003
22003
  trackPublish: (d) => n.trackPublish(u, d),
22004
22004
  trackAbandon: (d) => n.trackExplicitAbandon(u, d),
22005
22005
  trackFeature: (d) => n.trackFeature(u, d),
22006
- trackEditorFocus: () => n.trackEditorFocus(u),
22006
+ trackEditorFocus: (d) => n.trackEditorFocus(u, d),
22007
22007
  trackTabSwitch: (d, p) => n.trackTabSwitch(u, d, p),
22008
22008
  trackContentCreated: (d) => n.trackContentCreated(u, d),
22009
22009
  trackMediaUploadSuccess: (d) => n.trackMediaUploadSuccess(u, d),
@@ -39716,58 +39716,67 @@ const DialogClose = forwardRef((u, n) => /* @__PURE__ */ jsx(Close, { ref: n, "d
39716
39716
  }
39717
39717
  ));
39718
39718
  var PostBuilderEvents = /* @__PURE__ */ ((u) => (u.POST_PUBLISH_ATTEMPTED = "select:post_publish_attempted", u.POST_PUBLISH_SUCCESSFUL = "select:post_publish_success", u.POST_PUBLISH_FAILED = "select:post_publish_failed", u.POST_SESSION_ROTATED = "select:post_session_rotated", u.DRAFT_REHYDRATE_REQUEST = "select:draft_rehydrate_request", u))(PostBuilderEvents || {});
39719
+ const USER_INPUT_FOCUS_WINDOW_MS = 150;
39720
+ function classifyFocus(u, n) {
39721
+ return u !== null && n - u <= USER_INPUT_FOCUS_WINDOW_MS ? "user" : "auto";
39722
+ }
39719
39723
  function useEditorTracking({
39720
39724
  editor: u,
39721
39725
  editorType: n,
39722
39726
  idleTimeout: d = 3e5
39723
39727
  // 5 minutes default
39724
39728
  }) {
39725
- const { sessionId: p } = useAnalyticsSession(), m = useRef(), g = useRef(!1), y = useRef(!1), b = getAnalyticsStore(), S = useCallback(() => getEditorMetrics(u), [u]), E = useCallback(() => {
39726
- m.current && clearTimeout(m.current), !(!u || !p || y.current) && (m.current = setTimeout(() => {
39727
- const C = S();
39728
- C && !C.isEmpty && (b.trackExplicitAbandon(p, {
39729
- contentLength: C.characterCount,
39730
- hasUnsavedChanges: C.hasUnsavedChanges,
39729
+ const { sessionId: p } = useAnalyticsSession(), m = useRef(), g = useRef(!1), y = getAnalyticsStore(), b = useCallback(() => getEditorMetrics(u), [u]), S = useCallback(() => {
39730
+ m.current && clearTimeout(m.current), !(!u || !p || g.current) && (m.current = setTimeout(() => {
39731
+ const T = b();
39732
+ T && !T.isEmpty && (y.trackExplicitAbandon(p, {
39733
+ contentLength: T.characterCount,
39734
+ hasUnsavedChanges: T.hasUnsavedChanges,
39731
39735
  abandonReason: "idle_timeout"
39732
- }), y.current = !0);
39736
+ }), g.current = !0);
39733
39737
  }, d));
39734
- }, [u, p, d, b, S]), T = useCallback(() => {
39738
+ }, [u, p, d, y, b]), E = useCallback(() => {
39735
39739
  if (!u || !p) return;
39736
- const C = S();
39737
- C && (C.wordCount >= 1 || C.mediaCount > 0 || C.linkCount > 0 || C?.pollCount > 0) && b.trackContentCreated(p, {
39740
+ const T = b();
39741
+ T && (T.wordCount >= 1 || T.mediaCount > 0 || T.linkCount > 0 || T?.pollCount > 0) && y.trackContentCreated(p, {
39738
39742
  editorType: n,
39739
- wordCount: C.wordCount,
39740
- mediaCount: C.mediaCount,
39741
- linkCount: C.linkCount
39743
+ wordCount: T.wordCount,
39744
+ mediaCount: T.mediaCount,
39745
+ linkCount: T.linkCount
39742
39746
  });
39743
- }, [u, p, b, n, S]);
39747
+ }, [u, p, y, n, b]);
39744
39748
  useEffect(() => {
39745
39749
  if (!u || !p) return;
39746
- const C = () => {
39747
- g.current || (b.trackEditorFocus(p), g.current = !0, T()), E();
39748
- }, A = () => {
39749
- T(), E();
39750
+ let T = null;
39751
+ const C = (R) => {
39752
+ !(R.target instanceof Node) || !u.view.dom?.contains(R.target) || (T = performance.now(), y.trackEditorFocus(p, "user"));
39753
+ }, A = (R) => {
39754
+ R.key === "Tab" && (T = performance.now());
39755
+ }, k = () => {
39756
+ y.trackEditorFocus(p, classifyFocus(T, performance.now())), E(), S();
39757
+ }, _ = () => {
39758
+ E(), S();
39750
39759
  };
39751
- return u.on("focus", C), u.on("update", A), () => {
39752
- u.off("focus", C), u.off("update", A);
39760
+ return document.addEventListener("pointerdown", C, !0), document.addEventListener("keydown", A, !0), u.on("focus", k), u.on("update", _), () => {
39761
+ document.removeEventListener("pointerdown", C, !0), document.removeEventListener("keydown", A, !0), u.off("focus", k), u.off("update", _);
39753
39762
  };
39754
- }, [u, p, b, E, T]), useEffect(() => {
39763
+ }, [u, p, y, S, E]), useEffect(() => {
39755
39764
  if (!p) return;
39756
- const C = () => {
39757
- if (y.current) return;
39758
- const A = S();
39759
- A && !A.isEmpty && (b.trackExplicitAbandon(p, {
39760
- contentLength: A.characterCount,
39761
- hasUnsavedChanges: A.hasUnsavedChanges,
39765
+ const T = () => {
39766
+ if (g.current) return;
39767
+ const C = b();
39768
+ C && !C.isEmpty && (y.trackExplicitAbandon(p, {
39769
+ contentLength: C.characterCount,
39770
+ hasUnsavedChanges: C.hasUnsavedChanges,
39762
39771
  abandonReason: "navigation"
39763
- }), y.current = !0);
39772
+ }), g.current = !0);
39764
39773
  };
39765
- return window.addEventListener("beforeunload", C), () => {
39766
- window.removeEventListener("beforeunload", C), m.current && clearTimeout(m.current);
39774
+ return window.addEventListener("beforeunload", T), () => {
39775
+ window.removeEventListener("beforeunload", T), m.current && clearTimeout(m.current);
39767
39776
  };
39768
- }, [p, b, S]), useEffect(() => () => {
39769
- m.current && clearTimeout(m.current), b.deleteSession(p);
39770
- }, [b, p]);
39777
+ }, [p, y, b]), useEffect(() => () => {
39778
+ m.current && clearTimeout(m.current), y.deleteSession(p);
39779
+ }, [y, p]);
39771
39780
  }
39772
39781
  const useHostAnalyticsBridge = () => {
39773
39782
  const { sessionId: u, editorType: n, placement: d } = useAnalyticsSession(), p = useAnalyticsStore((b) => b.trackPublish), m = useAnalyticsStore((b) => b.deleteSession), g = useAnalyticsStore((b) => b.createSession), y = useRef(/* @__PURE__ */ new Set());
@@ -61075,7 +61084,7 @@ const PostBuilderEditor = ({
61075
61084
  const ye = (xe) => {
61076
61085
  if (!Z) return;
61077
61086
  const { newSessionId: me } = xe.detail;
61078
- te(me), Z.isFocused && se(me);
61087
+ te(me), Z.isFocused && se(me, "auto");
61079
61088
  };
61080
61089
  return window.addEventListener(
61081
61090
  PostBuilderEvents.POST_SESSION_ROTATED,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@select-org/select-post-builder",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "A reusable, extensible Post Builder widget for the Select platform and beyond.",
5
5
  "main": "./dist/post-builder.cjs.js",
6
6
  "module": "./dist/post-builder.js",