@loupfeed/react 0.1.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/LICENSE.md +114 -0
- package/dist/index.cjs +114 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +106 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 loupfeed
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to use,
|
|
27
|
+
copy, modify, create derivative works, publicly perform, publicly display and
|
|
28
|
+
redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or service
|
|
34
|
+
that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software that
|
|
39
|
+
exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee using
|
|
52
|
+
the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to the
|
|
59
|
+
infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software, you
|
|
68
|
+
must include a copy of or a link to these Terms and Conditions and not remove any
|
|
69
|
+
copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, INCLUDING
|
|
74
|
+
BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, NON-INFRINGEMENT AND TITLE.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
|
|
79
|
+
IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of the
|
|
84
|
+
Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following will
|
|
93
|
+
apply:
|
|
94
|
+
|
|
95
|
+
We hereby grant you a license to the Software under the Apache License, Version
|
|
96
|
+
2.0, a copy of which is available at https://www.apache.org/licenses/LICENSE-2.0.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## In plain language (non-binding summary)
|
|
101
|
+
|
|
102
|
+
This is a **Fair Source** license. You can:
|
|
103
|
+
|
|
104
|
+
- **Self-host and run loupfeed** for your own purposes — including inside a
|
|
105
|
+
company, on your own servers or cloud account, for your own products.
|
|
106
|
+
- Read, modify, fork, and redistribute the source.
|
|
107
|
+
|
|
108
|
+
The one thing you may **not** do is offer loupfeed (or something substantially
|
|
109
|
+
similar built from it) **as a competing commercial product or hosted service**.
|
|
110
|
+
|
|
111
|
+
Two years after each release is published, that version automatically becomes
|
|
112
|
+
available to you under the **Apache License 2.0** (fully open source).
|
|
113
|
+
|
|
114
|
+
This summary is for convenience only; the Terms and Conditions above govern.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var core = require('@loupfeed/core');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
// src/index.tsx
|
|
8
|
+
var FeedbackCtx = react.createContext(null);
|
|
9
|
+
function installNavigationBreadcrumbs() {
|
|
10
|
+
if (typeof window === "undefined") return () => {
|
|
11
|
+
};
|
|
12
|
+
let last = window.location.pathname + window.location.search;
|
|
13
|
+
const record = () => {
|
|
14
|
+
const to = window.location.pathname + window.location.search;
|
|
15
|
+
if (to === last) return;
|
|
16
|
+
core.addBreadcrumb({ category: "navigation", message: `${last} \u2192 ${to}`, data: { from: last, to } });
|
|
17
|
+
core.setContext("request", { url: window.location.href, route: window.location.pathname });
|
|
18
|
+
last = to;
|
|
19
|
+
};
|
|
20
|
+
const origPush = history.pushState;
|
|
21
|
+
const origReplace = history.replaceState;
|
|
22
|
+
history.pushState = function(...args) {
|
|
23
|
+
const r = origPush.apply(this, args);
|
|
24
|
+
record();
|
|
25
|
+
return r;
|
|
26
|
+
};
|
|
27
|
+
history.replaceState = function(...args) {
|
|
28
|
+
const r = origReplace.apply(this, args);
|
|
29
|
+
record();
|
|
30
|
+
return r;
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener("popstate", record);
|
|
33
|
+
return () => {
|
|
34
|
+
history.pushState = origPush;
|
|
35
|
+
history.replaceState = origReplace;
|
|
36
|
+
window.removeEventListener("popstate", record);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function installClickBreadcrumbs() {
|
|
40
|
+
if (typeof window === "undefined") return () => {
|
|
41
|
+
};
|
|
42
|
+
const onClick = (e) => {
|
|
43
|
+
if (core.overlay.isInspecting()) return;
|
|
44
|
+
const target = e.target;
|
|
45
|
+
const el = target?.closest('button, a, [role="button"], input[type="submit"]');
|
|
46
|
+
if (!el) return;
|
|
47
|
+
const text = (el.textContent ?? "").trim().slice(0, 60) || el.getAttribute("aria-label") || el.tagName.toLowerCase();
|
|
48
|
+
core.addBreadcrumb({
|
|
49
|
+
category: "ui.click",
|
|
50
|
+
level: "info",
|
|
51
|
+
message: text,
|
|
52
|
+
data: { tag: el.tagName.toLowerCase() }
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
window.addEventListener("click", onClick, true);
|
|
56
|
+
return () => window.removeEventListener("click", onClick, true);
|
|
57
|
+
}
|
|
58
|
+
function FeedbackProvider({
|
|
59
|
+
children,
|
|
60
|
+
root,
|
|
61
|
+
router = "history",
|
|
62
|
+
overlay: overlayOpts,
|
|
63
|
+
captureClicks = true
|
|
64
|
+
}) {
|
|
65
|
+
const [isInspecting, setIsInspecting] = react.useState(false);
|
|
66
|
+
react.useEffect(() => {
|
|
67
|
+
if (typeof document === "undefined") return;
|
|
68
|
+
const rootEl = root?.current ?? document.body;
|
|
69
|
+
const unmountOverlay = core.mountOverlay({
|
|
70
|
+
...overlayOpts,
|
|
71
|
+
root: rootEl,
|
|
72
|
+
onSubmit: async (input) => {
|
|
73
|
+
await core.captureFeedback(input);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const teardowns = [unmountOverlay];
|
|
77
|
+
if (router !== "none") teardowns.push(installNavigationBreadcrumbs());
|
|
78
|
+
if (captureClicks) teardowns.push(installClickBreadcrumbs());
|
|
79
|
+
return () => teardowns.forEach((fn) => fn());
|
|
80
|
+
}, []);
|
|
81
|
+
const value = react.useMemo(
|
|
82
|
+
() => ({
|
|
83
|
+
openInspector: () => {
|
|
84
|
+
core.overlay.open();
|
|
85
|
+
setIsInspecting(true);
|
|
86
|
+
},
|
|
87
|
+
closeInspector: () => {
|
|
88
|
+
core.overlay.close();
|
|
89
|
+
setIsInspecting(false);
|
|
90
|
+
},
|
|
91
|
+
submit: (input) => core.captureFeedback(input),
|
|
92
|
+
isInspecting,
|
|
93
|
+
isRecording: core.replay.isRecording()
|
|
94
|
+
}),
|
|
95
|
+
[isInspecting]
|
|
96
|
+
);
|
|
97
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FeedbackCtx.Provider, { value, children });
|
|
98
|
+
}
|
|
99
|
+
function useFeedback() {
|
|
100
|
+
const ctx = react.useContext(FeedbackCtx);
|
|
101
|
+
if (!ctx) throw new Error("useFeedback() must be used within <FeedbackProvider>");
|
|
102
|
+
return ctx;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.FeedbackProvider = FeedbackProvider;
|
|
106
|
+
exports.useFeedback = useFeedback;
|
|
107
|
+
Object.keys(core).forEach(function (k) {
|
|
108
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () { return core[k]; }
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=index.cjs.map
|
|
114
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["createContext","addBreadcrumb","setContext","overlay","useState","useEffect","mountOverlay","captureFeedback","useMemo","replay","jsx","useContext"],"mappings":";;;;;;;AA8CA,IAAM,WAAA,GAAcA,oBAA2C,IAAI,CAAA;AAiBnE,SAAS,4BAAA,GAA2C;AAClD,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,MAAM;AAAA,EAAC,CAAA;AACjD,EAAA,IAAI,IAAA,GAAO,MAAA,CAAO,QAAA,CAAS,QAAA,GAAW,OAAO,QAAA,CAAS,MAAA;AACtD,EAAA,MAAM,SAAS,MAAM;AACnB,IAAA,MAAM,EAAA,GAAK,MAAA,CAAO,QAAA,CAAS,QAAA,GAAW,OAAO,QAAA,CAAS,MAAA;AACtD,IAAA,IAAI,OAAO,IAAA,EAAM;AACjB,IAAAC,kBAAA,CAAc,EAAE,QAAA,EAAU,YAAA,EAAc,OAAA,EAAS,GAAG,IAAI,CAAA,QAAA,EAAM,EAAE,CAAA,CAAA,EAAI,MAAM,EAAE,IAAA,EAAM,IAAA,EAAM,EAAA,IAAM,CAAA;AAC9F,IAAAC,eAAA,CAAW,SAAA,EAAW,EAAE,GAAA,EAAK,MAAA,CAAO,QAAA,CAAS,MAAM,KAAA,EAAO,MAAA,CAAO,QAAA,CAAS,QAAA,EAAU,CAAA;AACpF,IAAA,IAAA,GAAO,EAAA;AAAA,EACT,CAAA;AACA,EAAA,MAAM,WAAW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AC,EAAA,KAAO,IAAI,CAAA;AAAA,EAG7C,CAAA,EAAG,EAAE,CAAA;AAEL,EAAA,MAAM,KAAA,GAAQC,aAAA;AAAA,IACZ,OAAO;AAAA,MACL,eAAe,MAAM;AACnB,QAAAL,YAAA,CAAQ,IAAA,EAAK;AACb,QAAA,eAAA,CAAgB,IAAI,CAAA;AAAA,MACtB,CAAA;AAAA,MACA,gBAAgB,MAAM;AACpB,QAAAA,YAAA,CAAQ,KAAA,EAAM;AACd,QAAA,eAAA,CAAgB,KAAK,CAAA;AAAA,MACvB,CAAA;AAAA,MACA,MAAA,EAAQ,CAAC,KAAA,KAAyBI,oBAAA,CAAgB,KAAK,CAAA;AAAA,MACvD,YAAA;AAAA,MACA,WAAA,EAAaE,YAAO,WAAA;AAAY,KAClC,CAAA;AAAA,IACA,CAAC,YAAY;AAAA,GACf;AAEA,EAAA,uBAAOC,cAAA,CAAC,WAAA,CAAY,QAAA,EAAZ,EAAqB,OAAe,QAAA,EAAS,CAAA;AACvD;AAEO,SAAS,WAAA,GAAoC;AAClD,EAAA,MAAM,GAAA,GAAMC,iBAAW,WAAW,CAAA;AAClC,EAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,sDAAsD,CAAA;AAChF,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * @loupfeed/react — thin adapter. The engine lives in @loupfeed/core; this only\n * (a) mounts the overlay into the React tree, and (b) wires router/click\n * breadcrumbs into the scope/context API.\n *\n * NOTE: the Vite plugin is intentionally NOT re-exported here. A runtime adapter\n * must never import a build package (privacy invariant, doc 03). Import the\n * plugin directly from `@loupfeed/vite-plugin` in your `vite.config`.\n */\n\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useState,\n type ReactNode,\n type RefObject,\n} from 'react';\nimport {\n addBreadcrumb,\n captureFeedback,\n mountOverlay,\n overlay,\n replay,\n setContext,\n type FeedbackInput,\n type OverlayOptions,\n} from '@loupfeed/core';\n\n// Re-export the full core public surface (init, scope API, types, …).\nexport * from '@loupfeed/core';\n\ntype FeedbackContextValue = {\n /** Enter element-inspect mode. */\n openInspector(): void;\n /** Leave inspect mode / close any open composer. */\n closeInspector(): void;\n /** Submit feedback programmatically. */\n submit(input: FeedbackInput): Promise<string>;\n /** Reflects programmatic inspect toggles (not the built-in launcher). */\n isInspecting: boolean;\n /** Session replay is deferred in the MVP — always false. */\n isRecording: boolean;\n};\n\nconst FeedbackCtx = createContext<FeedbackContextValue | null>(null);\n\nexport interface FeedbackProviderProps {\n children: ReactNode;\n /**\n * Root the selector engine generates structural paths relative to.\n * Defaults to `document.body`.\n */\n root?: RefObject<Element | null>;\n /** Router integration for auto-navigation breadcrumbs. Default 'history'. */\n router?: 'react-router' | 'tanstack' | 'history' | 'none';\n /** Overlay appearance/behavior (accent color, z-index, …). */\n overlay?: Omit<OverlayOptions, 'root' | 'onSubmit'>;\n /** Record `ui.click` breadcrumbs for button/link clicks. Default true. */\n captureClicks?: boolean;\n}\n\nfunction installNavigationBreadcrumbs(): () => void {\n if (typeof window === 'undefined') return () => {};\n let last = window.location.pathname + window.location.search;\n const record = () => {\n const to = window.location.pathname + window.location.search;\n if (to === last) return;\n addBreadcrumb({ category: 'navigation', message: `${last} → ${to}`, data: { from: last, to } });\n setContext('request', { url: window.location.href, route: window.location.pathname });\n last = to;\n };\n const origPush = history.pushState;\n const origReplace = history.replaceState;\n history.pushState = function (this: History, ...args: Parameters<History['pushState']>) {\n const r = origPush.apply(this, args);\n record();\n return r;\n };\n history.replaceState = function (this: History, ...args: Parameters<History['replaceState']>) {\n const r = origReplace.apply(this, args);\n record();\n return r;\n };\n window.addEventListener('popstate', record);\n return () => {\n history.pushState = origPush;\n history.replaceState = origReplace;\n window.removeEventListener('popstate', record);\n };\n}\n\nfunction installClickBreadcrumbs(): () => void {\n if (typeof window === 'undefined') return () => {};\n const onClick = (e: MouseEvent) => {\n if (overlay.isInspecting()) return; // inspect-mode clicks aren't app interactions\n const target = e.target as Element | null;\n const el = target?.closest('button, a, [role=\"button\"], input[type=\"submit\"]');\n if (!el) return;\n const text =\n (el.textContent ?? '').trim().slice(0, 60) ||\n el.getAttribute('aria-label') ||\n el.tagName.toLowerCase();\n addBreadcrumb({\n category: 'ui.click',\n level: 'info',\n message: text,\n data: { tag: el.tagName.toLowerCase() },\n });\n };\n window.addEventListener('click', onClick, true);\n return () => window.removeEventListener('click', onClick, true);\n}\n\nexport function FeedbackProvider({\n children,\n root,\n router = 'history',\n overlay: overlayOpts,\n captureClicks = true,\n}: FeedbackProviderProps): JSX.Element {\n const [isInspecting, setIsInspecting] = useState(false);\n\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const rootEl = root?.current ?? document.body;\n const unmountOverlay = mountOverlay({\n ...overlayOpts,\n root: rootEl,\n onSubmit: async (input) => {\n await captureFeedback(input);\n },\n });\n const teardowns: Array<() => void> = [unmountOverlay];\n if (router !== 'none') teardowns.push(installNavigationBreadcrumbs());\n if (captureClicks) teardowns.push(installClickBreadcrumbs());\n return () => teardowns.forEach((fn) => fn());\n // Mount once for the lifetime of the provider.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const value = useMemo<FeedbackContextValue>(\n () => ({\n openInspector: () => {\n overlay.open();\n setIsInspecting(true);\n },\n closeInspector: () => {\n overlay.close();\n setIsInspecting(false);\n },\n submit: (input: FeedbackInput) => captureFeedback(input),\n isInspecting,\n isRecording: replay.isRecording(),\n }),\n [isInspecting],\n );\n\n return <FeedbackCtx.Provider value={value}>{children}</FeedbackCtx.Provider>;\n}\n\nexport function useFeedback(): FeedbackContextValue {\n const ctx = useContext(FeedbackCtx);\n if (!ctx) throw new Error('useFeedback() must be used within <FeedbackProvider>');\n return ctx;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import { OverlayOptions, FeedbackInput } from '@loupfeed/core';
|
|
3
|
+
export * from '@loupfeed/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @loupfeed/react — thin adapter. The engine lives in @loupfeed/core; this only
|
|
7
|
+
* (a) mounts the overlay into the React tree, and (b) wires router/click
|
|
8
|
+
* breadcrumbs into the scope/context API.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: the Vite plugin is intentionally NOT re-exported here. A runtime adapter
|
|
11
|
+
* must never import a build package (privacy invariant, doc 03). Import the
|
|
12
|
+
* plugin directly from `@loupfeed/vite-plugin` in your `vite.config`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type FeedbackContextValue = {
|
|
16
|
+
/** Enter element-inspect mode. */
|
|
17
|
+
openInspector(): void;
|
|
18
|
+
/** Leave inspect mode / close any open composer. */
|
|
19
|
+
closeInspector(): void;
|
|
20
|
+
/** Submit feedback programmatically. */
|
|
21
|
+
submit(input: FeedbackInput): Promise<string>;
|
|
22
|
+
/** Reflects programmatic inspect toggles (not the built-in launcher). */
|
|
23
|
+
isInspecting: boolean;
|
|
24
|
+
/** Session replay is deferred in the MVP — always false. */
|
|
25
|
+
isRecording: boolean;
|
|
26
|
+
};
|
|
27
|
+
interface FeedbackProviderProps {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Root the selector engine generates structural paths relative to.
|
|
31
|
+
* Defaults to `document.body`.
|
|
32
|
+
*/
|
|
33
|
+
root?: RefObject<Element | null>;
|
|
34
|
+
/** Router integration for auto-navigation breadcrumbs. Default 'history'. */
|
|
35
|
+
router?: 'react-router' | 'tanstack' | 'history' | 'none';
|
|
36
|
+
/** Overlay appearance/behavior (accent color, z-index, …). */
|
|
37
|
+
overlay?: Omit<OverlayOptions, 'root' | 'onSubmit'>;
|
|
38
|
+
/** Record `ui.click` breadcrumbs for button/link clicks. Default true. */
|
|
39
|
+
captureClicks?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare function FeedbackProvider({ children, root, router, overlay: overlayOpts, captureClicks, }: FeedbackProviderProps): JSX.Element;
|
|
42
|
+
declare function useFeedback(): FeedbackContextValue;
|
|
43
|
+
|
|
44
|
+
export { FeedbackProvider, type FeedbackProviderProps, useFeedback };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ReactNode, RefObject } from 'react';
|
|
2
|
+
import { OverlayOptions, FeedbackInput } from '@loupfeed/core';
|
|
3
|
+
export * from '@loupfeed/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @loupfeed/react — thin adapter. The engine lives in @loupfeed/core; this only
|
|
7
|
+
* (a) mounts the overlay into the React tree, and (b) wires router/click
|
|
8
|
+
* breadcrumbs into the scope/context API.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: the Vite plugin is intentionally NOT re-exported here. A runtime adapter
|
|
11
|
+
* must never import a build package (privacy invariant, doc 03). Import the
|
|
12
|
+
* plugin directly from `@loupfeed/vite-plugin` in your `vite.config`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type FeedbackContextValue = {
|
|
16
|
+
/** Enter element-inspect mode. */
|
|
17
|
+
openInspector(): void;
|
|
18
|
+
/** Leave inspect mode / close any open composer. */
|
|
19
|
+
closeInspector(): void;
|
|
20
|
+
/** Submit feedback programmatically. */
|
|
21
|
+
submit(input: FeedbackInput): Promise<string>;
|
|
22
|
+
/** Reflects programmatic inspect toggles (not the built-in launcher). */
|
|
23
|
+
isInspecting: boolean;
|
|
24
|
+
/** Session replay is deferred in the MVP — always false. */
|
|
25
|
+
isRecording: boolean;
|
|
26
|
+
};
|
|
27
|
+
interface FeedbackProviderProps {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
/**
|
|
30
|
+
* Root the selector engine generates structural paths relative to.
|
|
31
|
+
* Defaults to `document.body`.
|
|
32
|
+
*/
|
|
33
|
+
root?: RefObject<Element | null>;
|
|
34
|
+
/** Router integration for auto-navigation breadcrumbs. Default 'history'. */
|
|
35
|
+
router?: 'react-router' | 'tanstack' | 'history' | 'none';
|
|
36
|
+
/** Overlay appearance/behavior (accent color, z-index, …). */
|
|
37
|
+
overlay?: Omit<OverlayOptions, 'root' | 'onSubmit'>;
|
|
38
|
+
/** Record `ui.click` breadcrumbs for button/link clicks. Default true. */
|
|
39
|
+
captureClicks?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare function FeedbackProvider({ children, root, router, overlay: overlayOpts, captureClicks, }: FeedbackProviderProps): JSX.Element;
|
|
42
|
+
declare function useFeedback(): FeedbackContextValue;
|
|
43
|
+
|
|
44
|
+
export { FeedbackProvider, type FeedbackProviderProps, useFeedback };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createContext, useState, useEffect, useMemo, useContext } from 'react';
|
|
2
|
+
import { mountOverlay, captureFeedback, replay, overlay, addBreadcrumb, setContext } from '@loupfeed/core';
|
|
3
|
+
export * from '@loupfeed/core';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/index.tsx
|
|
7
|
+
var FeedbackCtx = createContext(null);
|
|
8
|
+
function installNavigationBreadcrumbs() {
|
|
9
|
+
if (typeof window === "undefined") return () => {
|
|
10
|
+
};
|
|
11
|
+
let last = window.location.pathname + window.location.search;
|
|
12
|
+
const record = () => {
|
|
13
|
+
const to = window.location.pathname + window.location.search;
|
|
14
|
+
if (to === last) return;
|
|
15
|
+
addBreadcrumb({ category: "navigation", message: `${last} \u2192 ${to}`, data: { from: last, to } });
|
|
16
|
+
setContext("request", { url: window.location.href, route: window.location.pathname });
|
|
17
|
+
last = to;
|
|
18
|
+
};
|
|
19
|
+
const origPush = history.pushState;
|
|
20
|
+
const origReplace = history.replaceState;
|
|
21
|
+
history.pushState = function(...args) {
|
|
22
|
+
const r = origPush.apply(this, args);
|
|
23
|
+
record();
|
|
24
|
+
return r;
|
|
25
|
+
};
|
|
26
|
+
history.replaceState = function(...args) {
|
|
27
|
+
const r = origReplace.apply(this, args);
|
|
28
|
+
record();
|
|
29
|
+
return r;
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("popstate", record);
|
|
32
|
+
return () => {
|
|
33
|
+
history.pushState = origPush;
|
|
34
|
+
history.replaceState = origReplace;
|
|
35
|
+
window.removeEventListener("popstate", record);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function installClickBreadcrumbs() {
|
|
39
|
+
if (typeof window === "undefined") return () => {
|
|
40
|
+
};
|
|
41
|
+
const onClick = (e) => {
|
|
42
|
+
if (overlay.isInspecting()) return;
|
|
43
|
+
const target = e.target;
|
|
44
|
+
const el = target?.closest('button, a, [role="button"], input[type="submit"]');
|
|
45
|
+
if (!el) return;
|
|
46
|
+
const text = (el.textContent ?? "").trim().slice(0, 60) || el.getAttribute("aria-label") || el.tagName.toLowerCase();
|
|
47
|
+
addBreadcrumb({
|
|
48
|
+
category: "ui.click",
|
|
49
|
+
level: "info",
|
|
50
|
+
message: text,
|
|
51
|
+
data: { tag: el.tagName.toLowerCase() }
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
window.addEventListener("click", onClick, true);
|
|
55
|
+
return () => window.removeEventListener("click", onClick, true);
|
|
56
|
+
}
|
|
57
|
+
function FeedbackProvider({
|
|
58
|
+
children,
|
|
59
|
+
root,
|
|
60
|
+
router = "history",
|
|
61
|
+
overlay: overlayOpts,
|
|
62
|
+
captureClicks = true
|
|
63
|
+
}) {
|
|
64
|
+
const [isInspecting, setIsInspecting] = useState(false);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (typeof document === "undefined") return;
|
|
67
|
+
const rootEl = root?.current ?? document.body;
|
|
68
|
+
const unmountOverlay = mountOverlay({
|
|
69
|
+
...overlayOpts,
|
|
70
|
+
root: rootEl,
|
|
71
|
+
onSubmit: async (input) => {
|
|
72
|
+
await captureFeedback(input);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const teardowns = [unmountOverlay];
|
|
76
|
+
if (router !== "none") teardowns.push(installNavigationBreadcrumbs());
|
|
77
|
+
if (captureClicks) teardowns.push(installClickBreadcrumbs());
|
|
78
|
+
return () => teardowns.forEach((fn) => fn());
|
|
79
|
+
}, []);
|
|
80
|
+
const value = useMemo(
|
|
81
|
+
() => ({
|
|
82
|
+
openInspector: () => {
|
|
83
|
+
overlay.open();
|
|
84
|
+
setIsInspecting(true);
|
|
85
|
+
},
|
|
86
|
+
closeInspector: () => {
|
|
87
|
+
overlay.close();
|
|
88
|
+
setIsInspecting(false);
|
|
89
|
+
},
|
|
90
|
+
submit: (input) => captureFeedback(input),
|
|
91
|
+
isInspecting,
|
|
92
|
+
isRecording: replay.isRecording()
|
|
93
|
+
}),
|
|
94
|
+
[isInspecting]
|
|
95
|
+
);
|
|
96
|
+
return /* @__PURE__ */ jsx(FeedbackCtx.Provider, { value, children });
|
|
97
|
+
}
|
|
98
|
+
function useFeedback() {
|
|
99
|
+
const ctx = useContext(FeedbackCtx);
|
|
100
|
+
if (!ctx) throw new Error("useFeedback() must be used within <FeedbackProvider>");
|
|
101
|
+
return ctx;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { FeedbackProvider, useFeedback };
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;AA8CA,IAAM,WAAA,GAAc,cAA2C,IAAI,CAAA;AAiBnE,SAAS,4BAAA,GAA2C;AAClD,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,MAAM;AAAA,EAAC,CAAA;AACjD,EAAA,IAAI,IAAA,GAAO,MAAA,CAAO,QAAA,CAAS,QAAA,GAAW,OAAO,QAAA,CAAS,MAAA;AACtD,EAAA,MAAM,SAAS,MAAM;AACnB,IAAA,MAAM,EAAA,GAAK,MAAA,CAAO,QAAA,CAAS,QAAA,GAAW,OAAO,QAAA,CAAS,MAAA;AACtD,IAAA,IAAI,OAAO,IAAA,EA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(a) mounts the overlay into the React tree, and (b) wires router/click\n * breadcrumbs into the scope/context API.\n *\n * NOTE: the Vite plugin is intentionally NOT re-exported here. A runtime adapter\n * must never import a build package (privacy invariant, doc 03). Import the\n * plugin directly from `@loupfeed/vite-plugin` in your `vite.config`.\n */\n\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useState,\n type ReactNode,\n type RefObject,\n} from 'react';\nimport {\n addBreadcrumb,\n captureFeedback,\n mountOverlay,\n overlay,\n replay,\n setContext,\n type FeedbackInput,\n type OverlayOptions,\n} from '@loupfeed/core';\n\n// Re-export the full core public surface (init, scope API, types, …).\nexport * from '@loupfeed/core';\n\ntype FeedbackContextValue = {\n /** Enter element-inspect mode. */\n openInspector(): void;\n /** Leave inspect mode / close any open composer. */\n closeInspector(): void;\n /** Submit feedback programmatically. */\n submit(input: FeedbackInput): Promise<string>;\n /** Reflects programmatic inspect toggles (not the built-in launcher). */\n isInspecting: boolean;\n /** Session replay is deferred in the MVP — always false. */\n isRecording: boolean;\n};\n\nconst FeedbackCtx = createContext<FeedbackContextValue | null>(null);\n\nexport interface FeedbackProviderProps {\n children: ReactNode;\n /**\n * Root the selector engine generates structural paths relative to.\n * Defaults to `document.body`.\n */\n root?: RefObject<Element | null>;\n /** Router integration for auto-navigation breadcrumbs. Default 'history'. */\n router?: 'react-router' | 'tanstack' | 'history' | 'none';\n /** Overlay appearance/behavior (accent color, z-index, …). */\n overlay?: Omit<OverlayOptions, 'root' | 'onSubmit'>;\n /** Record `ui.click` breadcrumbs for button/link clicks. Default true. */\n captureClicks?: boolean;\n}\n\nfunction installNavigationBreadcrumbs(): () => void {\n if (typeof window === 'undefined') return () => {};\n let last = window.location.pathname + window.location.search;\n const record = () => {\n const to = window.location.pathname + window.location.search;\n if (to === last) return;\n addBreadcrumb({ category: 'navigation', message: `${last} → ${to}`, data: { from: last, to } });\n setContext('request', { url: window.location.href, route: window.location.pathname });\n last = to;\n };\n const origPush = history.pushState;\n const origReplace = history.replaceState;\n history.pushState = function (this: History, ...args: Parameters<History['pushState']>) {\n const r = origPush.apply(this, args);\n record();\n return r;\n };\n history.replaceState = function (this: History, ...args: Parameters<History['replaceState']>) {\n const r = origReplace.apply(this, args);\n record();\n return r;\n };\n window.addEventListener('popstate', record);\n return () => {\n history.pushState = origPush;\n history.replaceState = origReplace;\n window.removeEventListener('popstate', record);\n };\n}\n\nfunction installClickBreadcrumbs(): () => void {\n if (typeof window === 'undefined') return () => {};\n const onClick = (e: MouseEvent) => {\n if (overlay.isInspecting()) return; // inspect-mode clicks aren't app interactions\n const target = e.target as Element | null;\n const el = target?.closest('button, a, [role=\"button\"], input[type=\"submit\"]');\n if (!el) return;\n const text =\n (el.textContent ?? '').trim().slice(0, 60) ||\n el.getAttribute('aria-label') ||\n el.tagName.toLowerCase();\n addBreadcrumb({\n category: 'ui.click',\n level: 'info',\n message: text,\n data: { tag: el.tagName.toLowerCase() },\n });\n };\n window.addEventListener('click', onClick, true);\n return () => window.removeEventListener('click', onClick, true);\n}\n\nexport function FeedbackProvider({\n children,\n root,\n router = 'history',\n overlay: overlayOpts,\n captureClicks = true,\n}: FeedbackProviderProps): JSX.Element {\n const [isInspecting, setIsInspecting] = useState(false);\n\n useEffect(() => {\n if (typeof document === 'undefined') return;\n const rootEl = root?.current ?? document.body;\n const unmountOverlay = mountOverlay({\n ...overlayOpts,\n root: rootEl,\n onSubmit: async (input) => {\n await captureFeedback(input);\n },\n });\n const teardowns: Array<() => void> = [unmountOverlay];\n if (router !== 'none') teardowns.push(installNavigationBreadcrumbs());\n if (captureClicks) teardowns.push(installClickBreadcrumbs());\n return () => teardowns.forEach((fn) => fn());\n // Mount once for the lifetime of the provider.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const value = useMemo<FeedbackContextValue>(\n () => ({\n openInspector: () => {\n overlay.open();\n setIsInspecting(true);\n },\n closeInspector: () => {\n overlay.close();\n setIsInspecting(false);\n },\n submit: (input: FeedbackInput) => captureFeedback(input),\n isInspecting,\n isRecording: replay.isRecording(),\n }),\n [isInspecting],\n );\n\n return <FeedbackCtx.Provider value={value}>{children}</FeedbackCtx.Provider>;\n}\n\nexport function useFeedback(): FeedbackContextValue {\n const ctx = useContext(FeedbackCtx);\n if (!ctx) throw new Error('useFeedback() must be used within <FeedbackProvider>');\n return ctx;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loupfeed/react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "loupfeed React adapter — init(), <FeedbackProvider>, useFeedback(). Mounts the element-anchored feedback overlay and wires router/click breadcrumbs.",
|
|
5
|
+
"license": "FSL-1.1-ALv2",
|
|
6
|
+
"homepage": "https://loupfeed.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/gilons/loupfeed.git",
|
|
10
|
+
"directory": "packages/react"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "./dist/index.cjs",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@loupfeed/core": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^18.3.18",
|
|
40
|
+
"react": "^18.3.1",
|
|
41
|
+
"tsup": "^8.3.5",
|
|
42
|
+
"typescript": "~5.7.2"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"clean": "rm -rf dist .turbo"
|
|
49
|
+
}
|
|
50
|
+
}
|