@aglyn/plugins-workflows 1.0.0-beta.246 → 1.0.0-beta.249

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.
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import { elementPickUrl, isElementPickMessage } from "@aglyn/aglyn/app-utils/element-pick-protocol";
19
+ import { siteLiveUrlForSlug } from "@aglyn/aglyn/app-utils/site-live-url";
20
+ import { Alert, Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, TextField, Typography } from "@mui/material";
21
+ import { doc, getDoc } from "firebase/firestore";
22
+ import { useEffect, useMemo, useRef, useState } from "react";
23
+ import { useFirestore } from "@aglyn/tenant-feature-instance";
24
+ /** How long a page gets to answer before the dialog says it did not. */ const READY_TIMEOUT_MS = 10000;
25
+ /**
26
+ * The site's published pages as the picker lists them, home first. The
27
+ * routing map stores the root as `/` and every other page as bare segments
28
+ * (`about`); a site with nothing published still offers its home, which is
29
+ * what the dialog then says has not answered.
30
+ */ export function pickerPages(screens) {
31
+ const paths = new Set();
32
+ for (const slug of Object.values(screens != null ? screens : {})){
33
+ if (typeof slug !== 'string' || !slug) continue;
34
+ paths.add(slug.startsWith('/') ? slug : `/${slug}`);
35
+ }
36
+ if (!paths.size) paths.add('/');
37
+ return [
38
+ ...paths
39
+ ].sort((a, b)=>a === '/' ? -1 : b === '/' ? 1 : a.localeCompare(b)).map((path)=>({
40
+ path,
41
+ label: path === '/' ? 'Home' : path
42
+ }));
43
+ }
44
+ /**
45
+ * The live-page element picker (AGL-3758): the site's page in a frame, in
46
+ * pick mode, and the selector of whatever the builder clicks. Only a message
47
+ * from THAT frame, from the page's own origin, is read.
48
+ */ export default function ElementPickerDialog(props) {
49
+ const { hostId, initialPath, onPicked, onClose } = props;
50
+ const firestore = useFirestore();
51
+ const frame = useRef(null);
52
+ const [host, setHost] = useState(undefined);
53
+ const [path, setPath] = useState(null);
54
+ const [ready, setReady] = useState(false);
55
+ const [timedOut, setTimedOut] = useState(false);
56
+ // The caller's handlers, current without re-arming the listener below.
57
+ const handlers = useRef({
58
+ onPicked,
59
+ onClose
60
+ });
61
+ handlers.current = {
62
+ onPicked,
63
+ onClose
64
+ };
65
+ useEffect(()=>{
66
+ let live = true;
67
+ getDoc(doc(firestore, 'hosts', hostId)).then((snapshot)=>{
68
+ if (live) setHost(snapshot.exists() ? snapshot.data() : null);
69
+ }).catch(()=>{
70
+ if (live) setHost(null);
71
+ });
72
+ return ()=>{
73
+ live = false;
74
+ };
75
+ }, [
76
+ firestore,
77
+ hostId
78
+ ]);
79
+ const pages = useMemo(()=>pickerPages(host == null ? void 0 : host.screens), [
80
+ host
81
+ ]);
82
+ const current = path != null ? path : initialPath && pages.some((page)=>page.path === initialPath) ? initialPath : pages[0].path;
83
+ const pageUrl = host ? siteLiveUrlForSlug(host, current) : undefined;
84
+ const src = pageUrl ? elementPickUrl(pageUrl) : undefined;
85
+ useEffect(()=>{
86
+ if (!src) return undefined;
87
+ setReady(false);
88
+ setTimedOut(false);
89
+ const origin = new URL(src).origin;
90
+ const onMessage = (event)=>{
91
+ var _frame_current;
92
+ if (event.source !== ((_frame_current = frame.current) == null ? void 0 : _frame_current.contentWindow)) return;
93
+ if (event.origin !== origin) return;
94
+ if (!isElementPickMessage(event.data)) return;
95
+ if (event.data.event === 'ready') setReady(true);
96
+ else if (event.data.event === 'cancel') handlers.current.onClose();
97
+ else handlers.current.onPicked(event.data.selector, event.data.label);
98
+ };
99
+ window.addEventListener('message', onMessage);
100
+ const timer = window.setTimeout(()=>setTimedOut(true), READY_TIMEOUT_MS);
101
+ return ()=>{
102
+ window.removeEventListener('message', onMessage);
103
+ window.clearTimeout(timer);
104
+ };
105
+ }, [
106
+ src
107
+ ]);
108
+ return /*#__PURE__*/ _jsxs(Dialog, {
109
+ open: true,
110
+ onClose: onClose,
111
+ fullWidth: true,
112
+ maxWidth: "lg",
113
+ children: [
114
+ /*#__PURE__*/ _jsx(DialogTitle, {
115
+ children: 'Pick an element'
116
+ }),
117
+ /*#__PURE__*/ _jsx(DialogContent, {
118
+ children: /*#__PURE__*/ _jsxs(Stack, {
119
+ spacing: 1.5,
120
+ children: [
121
+ /*#__PURE__*/ _jsxs(Stack, {
122
+ direction: "row",
123
+ spacing: 2,
124
+ sx: {
125
+ alignItems: 'center'
126
+ },
127
+ children: [
128
+ /*#__PURE__*/ _jsx(TextField, {
129
+ select: true,
130
+ label: "Page",
131
+ value: current,
132
+ onChange: (event)=>setPath(event.target.value),
133
+ size: "small",
134
+ sx: {
135
+ minWidth: 220
136
+ },
137
+ disabled: !host,
138
+ children: pages.map((page)=>/*#__PURE__*/ _jsx(MenuItem, {
139
+ value: page.path,
140
+ children: page.label
141
+ }, page.path))
142
+ }),
143
+ /*#__PURE__*/ _jsx(Typography, {
144
+ variant: "body2",
145
+ color: "text.secondary",
146
+ children: ready ? 'Click the element on the page below.' : 'Opening the page…'
147
+ })
148
+ ]
149
+ }),
150
+ host === null || host && !src ? /*#__PURE__*/ _jsx(Alert, {
151
+ severity: "warning",
152
+ children: 'This site has no address to open yet. Use a custom selector instead.'
153
+ }) : null,
154
+ timedOut && !ready ? /*#__PURE__*/ _jsx(Alert, {
155
+ severity: "info",
156
+ children: 'The page has not answered. Publish the site and try again, or use ' + 'a custom selector.'
157
+ }) : null,
158
+ src ? /*#__PURE__*/ _jsx(Box, {
159
+ component: "iframe",
160
+ ref: frame,
161
+ src: src,
162
+ title: "Site page to pick from",
163
+ sx: {
164
+ width: '100%',
165
+ height: '65vh',
166
+ border: 1,
167
+ borderColor: 'divider',
168
+ borderRadius: 1,
169
+ bgcolor: 'background.paper'
170
+ }
171
+ }, src) : null
172
+ ]
173
+ })
174
+ }),
175
+ /*#__PURE__*/ _jsx(DialogActions, {
176
+ children: /*#__PURE__*/ _jsx(Button, {
177
+ onClick: onClose,
178
+ children: 'Cancel'
179
+ })
180
+ })
181
+ ]
182
+ });
183
+ }
184
+
185
+ //# sourceMappingURL=element-picker-dialog.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/element-picker-dialog.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport type { AglynHost } from '@aglyn/aglyn'\nimport {\n elementPickUrl,\n isElementPickMessage,\n} from '@aglyn/aglyn/app-utils/element-pick-protocol'\nimport { siteLiveUrlForSlug } from '@aglyn/aglyn/app-utils/site-live-url'\nimport {\n Alert,\n Box,\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc, getDoc } from 'firebase/firestore'\nimport { useEffect, useMemo, useRef, useState } from 'react'\nimport { useFirestore } from '@aglyn/tenant-feature-instance'\n\n/** How long a page gets to answer before the dialog says it did not. */\nconst READY_TIMEOUT_MS = 10_000\n\nexport interface ElementPickerDialogProps {\n hostId: string\n /** The page to open first; the home page when absent or not published. */\n initialPath?: string\n onPicked: (selector: string, label: string) => void\n onClose: () => void\n}\n\n/**\n * The site's published pages as the picker lists them, home first. The\n * routing map stores the root as `/` and every other page as bare segments\n * (`about`); a site with nothing published still offers its home, which is\n * what the dialog then says has not answered.\n */\nexport function pickerPages(\n screens: Record<string, string> | undefined,\n): { path: string; label: string }[] {\n const paths = new Set<string>()\n for (const slug of Object.values(screens ?? {})) {\n if (typeof slug !== 'string' || !slug) continue\n paths.add(slug.startsWith('/') ? slug : `/${slug}`)\n }\n if (!paths.size) paths.add('/')\n return [...paths]\n .sort((a, b) => (a === '/' ? -1 : b === '/' ? 1 : a.localeCompare(b)))\n .map((path) => ({ path, label: path === '/' ? 'Home' : path }))\n}\n\n/**\n * The live-page element picker (AGL-3758): the site's page in a frame, in\n * pick mode, and the selector of whatever the builder clicks. Only a message\n * from THAT frame, from the page's own origin, is read.\n */\nexport default function ElementPickerDialog(props: ElementPickerDialogProps) {\n const { hostId, initialPath, onPicked, onClose } = props\n const firestore = useFirestore()\n const frame = useRef<HTMLIFrameElement | null>(null)\n const [host, setHost] = useState<AglynHost | null | undefined>(undefined)\n const [path, setPath] = useState<string | null>(null)\n const [ready, setReady] = useState(false)\n const [timedOut, setTimedOut] = useState(false)\n // The caller's handlers, current without re-arming the listener below.\n const handlers = useRef({ onPicked, onClose })\n handlers.current = { onPicked, onClose }\n\n useEffect(() => {\n let live = true\n getDoc(doc(firestore, 'hosts', hostId))\n .then((snapshot) => {\n if (live) setHost(snapshot.exists() ? (snapshot.data() as AglynHost) : null)\n })\n .catch(() => {\n if (live) setHost(null)\n })\n return () => {\n live = false\n }\n }, [firestore, hostId])\n\n const pages = useMemo(\n () => pickerPages(host?.screens as Record<string, string> | undefined),\n [host],\n )\n const current =\n path ??\n (initialPath && pages.some((page) => page.path === initialPath)\n ? initialPath\n : pages[0].path)\n const pageUrl = host ? siteLiveUrlForSlug(host, current) : undefined\n const src = pageUrl ? elementPickUrl(pageUrl) : undefined\n\n useEffect(() => {\n if (!src) return undefined\n setReady(false)\n setTimedOut(false)\n const origin = new URL(src).origin\n const onMessage = (event: MessageEvent) => {\n if (event.source !== frame.current?.contentWindow) return\n if (event.origin !== origin) return\n if (!isElementPickMessage(event.data)) return\n if (event.data.event === 'ready') setReady(true)\n else if (event.data.event === 'cancel') handlers.current.onClose()\n else handlers.current.onPicked(event.data.selector, event.data.label)\n }\n window.addEventListener('message', onMessage)\n const timer = window.setTimeout(() => setTimedOut(true), READY_TIMEOUT_MS)\n return () => {\n window.removeEventListener('message', onMessage)\n window.clearTimeout(timer)\n }\n }, [src])\n\n return (\n <Dialog open onClose={onClose} fullWidth maxWidth=\"lg\">\n <DialogTitle>{'Pick an element'}</DialogTitle>\n <DialogContent>\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={2} sx={{ alignItems: 'center' }}>\n <TextField\n select\n label=\"Page\"\n value={current}\n onChange={(event) => setPath(event.target.value)}\n size=\"small\"\n sx={{ minWidth: 220 }}\n disabled={!host}\n >\n {pages.map((page) => (\n <MenuItem key={page.path} value={page.path}>\n {page.label}\n </MenuItem>\n ))}\n </TextField>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {ready\n ? 'Click the element on the page below.'\n : 'Opening the page…'}\n </Typography>\n </Stack>\n {host === null || (host && !src) ? (\n <Alert severity=\"warning\">\n {'This site has no address to open yet. Use a custom selector instead.'}\n </Alert>\n ) : null}\n {timedOut && !ready ? (\n <Alert severity=\"info\">\n {'The page has not answered. Publish the site and try again, or use ' +\n 'a custom selector.'}\n </Alert>\n ) : null}\n {src ? (\n <Box\n component=\"iframe\"\n ref={frame}\n key={src}\n src={src}\n title=\"Site page to pick from\"\n sx={{\n width: '100%',\n height: '65vh',\n border: 1,\n borderColor: 'divider',\n borderRadius: 1,\n bgcolor: 'background.paper',\n }}\n />\n ) : null}\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Cancel'}</Button>\n </DialogActions>\n </Dialog>\n )\n}\n"],"names":["elementPickUrl","isElementPickMessage","siteLiveUrlForSlug","Alert","Box","Button","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","TextField","Typography","doc","getDoc","useEffect","useMemo","useRef","useState","useFirestore","READY_TIMEOUT_MS","pickerPages","screens","paths","Set","slug","Object","values","add","startsWith","size","sort","a","b","localeCompare","map","path","label","ElementPickerDialog","props","hostId","initialPath","onPicked","onClose","firestore","frame","host","setHost","undefined","setPath","ready","setReady","timedOut","setTimedOut","handlers","current","live","then","snapshot","exists","data","catch","pages","some","page","pageUrl","src","origin","URL","onMessage","event","source","contentWindow","selector","window","addEventListener","timer","setTimeout","removeEventListener","clearTimeout","open","fullWidth","maxWidth","spacing","direction","sx","alignItems","select","value","onChange","target","minWidth","disabled","variant","color","severity","component","ref","title","width","height","border","borderColor","borderRadius","bgcolor","onClick"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAGA,SACEA,cAAc,EACdC,oBAAoB,QACf,+CAA8C;AACrD,SAASC,kBAAkB,QAAQ,uCAAsC;AACzE,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,EAAEC,MAAM,QAAQ,qBAAoB;AAChD,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAC5D,SAASC,YAAY,QAAQ,iCAAgC;AAE7D,sEAAsE,GACtE,MAAMC,mBAAmB;AAUzB;;;;;CAKC,GACD,OAAO,SAASC,YACdC,OAA2C;IAE3C,MAAMC,QAAQ,IAAIC;IAClB,KAAK,MAAMC,QAAQC,OAAOC,MAAM,CAACL,kBAAAA,UAAW,CAAC,GAAI;QAC/C,IAAI,OAAOG,SAAS,YAAY,CAACA,MAAM;QACvCF,MAAMK,GAAG,CAACH,KAAK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,KAAC3E;oCACC4E,MAAM;oCACNlD,OAAM;oCACNmD,OAAOjC;oCACPkC,UAAU,CAACnB,QAAUrB,QAAQqB,MAAMoB,MAAM,CAACF,KAAK;oCAC/C1D,MAAK;oCACLuD,IAAI;wCAAEM,UAAU;oCAAI;oCACpBC,UAAU,CAAC9C;8CAEVgB,MAAM3B,GAAG,CAAC,CAAC6B,qBACV,KAACvD;4CAAyB+E,OAAOxB,KAAK5B,IAAI;sDACvC4B,KAAK3B,KAAK;2CADE2B,KAAK5B,IAAI;;8CAK5B,KAACxB;oCAAWiF,SAAQ;oCAAQC,OAAM;8CAC/B5C,QACG,yCACA;;;;wBAGPJ,SAAS,QAASA,QAAQ,CAACoB,oBAC1B,KAAChE;4BAAM6F,UAAS;sCACb;6BAED;wBACH3C,YAAY,CAACF,sBACZ,KAAChD;4BAAM6F,UAAS;sCACb,uEACC;6BAEF;wBACH7B,oBACC,KAAC/D;4BACC6F,WAAU;4BACVC,KAAKpD;4BAELqB,KAAKA;4BACLgC,OAAM;4BACNb,IAAI;gCACFc,OAAO;gCACPC,QAAQ;gCACRC,QAAQ;gCACRC,aAAa;gCACbC,cAAc;gCACdC,SAAS;4BACX;2BAVKtC,OAYL;;;;0BAGR,KAAC5D;0BACC,cAAA,KAACF;oBAAOqG,SAAS9D;8BAAU;;;;;AAInC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export interface ElementSelectorFieldProps {
18
+ /** What the field targets, as the step or trigger names it. */
19
+ label: string;
20
+ /** The stored selector. */
21
+ value: string;
22
+ onChange: (value: string) => void;
23
+ /**
24
+ * The site whose pages the picker opens. Without one (an editor that is
25
+ * not about one site) the field is the custom selector alone.
26
+ */
27
+ hostId?: string;
28
+ /** The page the picker opens first, e.g. the trigger's "Only on pages". */
29
+ initialPath?: string;
30
+ /** What an empty field does, e.g. "Header or nav". */
31
+ emptyLabel?: string;
32
+ placeholder?: string;
33
+ }
34
+ /**
35
+ * An element target picked on the live page (AGL-3758). "Pick element"
36
+ * opens the site's page in a frame and the builder clicks the element; the
37
+ * stored selector is the one the Besigner's Interactions picker stores. A
38
+ * typed CSS selector is still there, behind "Use a custom selector".
39
+ */
40
+ export declare function ElementSelectorField(props: ElementSelectorFieldProps): import("react").JSX.Element;
41
+ export default ElementSelectorField;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ 'use client';
17
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
+ import { Button, Chip, Collapse, Link, Stack, TextField, Tooltip } from "@mui/material";
19
+ import { lazy, Suspense, useState } from "react";
20
+ // The picker frame is its own chunk: an Actions editor that never picks an
21
+ // element never downloads it.
22
+ const ElementPickerDialog = /*#__PURE__*/ lazy(()=>import("./element-picker-dialog.component.js"));
23
+ /** The stored form of a picked element: the renderer's leaf stamp. */ const LEAF_SELECTOR = /^\[data-aglyn="leaf:[^"]+"\]$/;
24
+ /**
25
+ * An element target picked on the live page (AGL-3758). "Pick element"
26
+ * opens the site's page in a frame and the builder clicks the element; the
27
+ * stored selector is the one the Besigner's Interactions picker stores. A
28
+ * typed CSS selector is still there, behind "Use a custom selector".
29
+ */ export function ElementSelectorField(props) {
30
+ const { label, value, onChange, hostId, initialPath, emptyLabel, placeholder } = props;
31
+ const [picking, setPicking] = useState(false);
32
+ const [pickedLabel, setPickedLabel] = useState(null);
33
+ const custom = Boolean(value) && !LEAF_SELECTOR.test(value);
34
+ const [advanced, setAdvanced] = useState(custom);
35
+ const customField = /*#__PURE__*/ _jsx(TextField, {
36
+ label: hostId ? 'Custom selector' : label,
37
+ value: value,
38
+ onChange: (event)=>{
39
+ setPickedLabel(null);
40
+ onChange(event.target.value);
41
+ },
42
+ size: "small",
43
+ fullWidth: true,
44
+ placeholder: placeholder,
45
+ helperText: hostId ? 'Any CSS selector; it replaces the picked element' : undefined
46
+ });
47
+ if (!hostId) return /*#__PURE__*/ _jsx(Stack, {
48
+ sx: {
49
+ flex: 1
50
+ },
51
+ children: customField
52
+ });
53
+ const chip = !value ? emptyLabel != null ? emptyLabel : 'No element yet' : custom ? value : pickedLabel != null ? pickedLabel : 'Picked element';
54
+ return /*#__PURE__*/ _jsxs(Stack, {
55
+ spacing: 0.5,
56
+ sx: {
57
+ flex: 1,
58
+ minWidth: 0
59
+ },
60
+ children: [
61
+ /*#__PURE__*/ _jsxs(Stack, {
62
+ useFlexGap: true,
63
+ direction: "row",
64
+ spacing: 1,
65
+ sx: {
66
+ alignItems: 'center',
67
+ flexWrap: 'wrap'
68
+ },
69
+ children: [
70
+ /*#__PURE__*/ _jsx(Button, {
71
+ size: "small",
72
+ variant: "outlined",
73
+ onClick: ()=>setPicking(true),
74
+ children: value ? `Change ${label.toLowerCase()}` : `Pick ${label.toLowerCase()}`
75
+ }),
76
+ /*#__PURE__*/ _jsx(Tooltip, {
77
+ title: value || '',
78
+ children: /*#__PURE__*/ _jsx(Chip, {
79
+ size: "small",
80
+ label: chip,
81
+ variant: value ? 'filled' : 'outlined',
82
+ color: value ? 'primary' : 'default',
83
+ onDelete: value ? ()=>onChange('') : undefined,
84
+ sx: {
85
+ maxWidth: 260
86
+ }
87
+ })
88
+ })
89
+ ]
90
+ }),
91
+ /*#__PURE__*/ _jsx(Link, {
92
+ component: "button",
93
+ type: "button",
94
+ variant: "caption",
95
+ underline: "hover",
96
+ onClick: ()=>setAdvanced((open)=>!open),
97
+ sx: {
98
+ alignSelf: 'flex-start'
99
+ },
100
+ children: advanced ? 'Hide custom selector' : 'Use a custom selector'
101
+ }),
102
+ /*#__PURE__*/ _jsx(Collapse, {
103
+ in: advanced,
104
+ unmountOnExit: true,
105
+ children: customField
106
+ }),
107
+ picking ? /*#__PURE__*/ _jsx(Suspense, {
108
+ fallback: null,
109
+ children: /*#__PURE__*/ _jsx(ElementPickerDialog, {
110
+ hostId: hostId,
111
+ initialPath: initialPath,
112
+ onClose: ()=>setPicking(false),
113
+ onPicked: (selector, picked)=>{
114
+ setPickedLabel(picked);
115
+ setAdvanced(false);
116
+ onChange(selector);
117
+ setPicking(false);
118
+ }
119
+ })
120
+ }) : null
121
+ ]
122
+ });
123
+ }
124
+ export default ElementSelectorField;
125
+
126
+ //# sourceMappingURL=element-selector-field.component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/element-selector-field.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n'use client'\n\nimport {\n Button,\n Chip,\n Collapse,\n Link,\n Stack,\n TextField,\n Tooltip,\n} from '@mui/material'\nimport { lazy, Suspense, useState } from 'react'\n\n// The picker frame is its own chunk: an Actions editor that never picks an\n// element never downloads it.\nconst ElementPickerDialog = lazy(() => import('./element-picker-dialog.component'))\n\n/** The stored form of a picked element: the renderer's leaf stamp. */\nconst LEAF_SELECTOR = /^\\[data-aglyn=\"leaf:[^\"]+\"\\]$/\n\nexport interface ElementSelectorFieldProps {\n /** What the field targets, as the step or trigger names it. */\n label: string\n /** The stored selector. */\n value: string\n onChange: (value: string) => void\n /**\n * The site whose pages the picker opens. Without one (an editor that is\n * not about one site) the field is the custom selector alone.\n */\n hostId?: string\n /** The page the picker opens first, e.g. the trigger's \"Only on pages\". */\n initialPath?: string\n /** What an empty field does, e.g. \"Header or nav\". */\n emptyLabel?: string\n placeholder?: string\n}\n\n/**\n * An element target picked on the live page (AGL-3758). \"Pick element\"\n * opens the site's page in a frame and the builder clicks the element; the\n * stored selector is the one the Besigner's Interactions picker stores. A\n * typed CSS selector is still there, behind \"Use a custom selector\".\n */\nexport function ElementSelectorField(props: ElementSelectorFieldProps) {\n const { label, value, onChange, hostId, initialPath, emptyLabel, placeholder } =\n props\n const [picking, setPicking] = useState(false)\n const [pickedLabel, setPickedLabel] = useState<string | null>(null)\n const custom = Boolean(value) && !LEAF_SELECTOR.test(value)\n const [advanced, setAdvanced] = useState(custom)\n\n const customField = (\n <TextField\n label={hostId ? 'Custom selector' : label}\n value={value}\n onChange={(event) => {\n setPickedLabel(null)\n onChange(event.target.value)\n }}\n size=\"small\"\n fullWidth\n placeholder={placeholder}\n helperText={hostId ? 'Any CSS selector; it replaces the picked element' : undefined}\n />\n )\n if (!hostId) return <Stack sx={{ flex: 1 }}>{customField}</Stack>\n\n const chip = !value\n ? (emptyLabel ?? 'No element yet')\n : custom\n ? value\n : (pickedLabel ?? 'Picked element')\n return (\n <Stack spacing={0.5} sx={{ flex: 1, minWidth: 0 }}>\n <Stack\n useFlexGap\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center', flexWrap: 'wrap' }}\n >\n <Button size=\"small\" variant=\"outlined\" onClick={() => setPicking(true)}>\n {value ? `Change ${label.toLowerCase()}` : `Pick ${label.toLowerCase()}`}\n </Button>\n <Tooltip title={value || ''}>\n <Chip\n size=\"small\"\n label={chip}\n variant={value ? 'filled' : 'outlined'}\n color={value ? 'primary' : 'default'}\n onDelete={value ? () => onChange('') : undefined}\n sx={{ maxWidth: 260 }}\n />\n </Tooltip>\n </Stack>\n <Link\n component=\"button\"\n type=\"button\"\n variant=\"caption\"\n underline=\"hover\"\n onClick={() => setAdvanced((open) => !open)}\n sx={{ alignSelf: 'flex-start' }}\n >\n {advanced ? 'Hide custom selector' : 'Use a custom selector'}\n </Link>\n <Collapse in={advanced} unmountOnExit>\n {customField}\n </Collapse>\n {picking ? (\n <Suspense fallback={null}>\n <ElementPickerDialog\n hostId={hostId}\n initialPath={initialPath}\n onClose={() => setPicking(false)}\n onPicked={(selector, picked) => {\n setPickedLabel(picked)\n setAdvanced(false)\n onChange(selector)\n setPicking(false)\n }}\n />\n </Suspense>\n ) : null}\n </Stack>\n )\n}\n\nexport default ElementSelectorField\n"],"names":["Button","Chip","Collapse","Link","Stack","TextField","Tooltip","lazy","Suspense","useState","ElementPickerDialog","LEAF_SELECTOR","ElementSelectorField","props","label","value","onChange","hostId","initialPath","emptyLabel","placeholder","picking","setPicking","pickedLabel","setPickedLabel","custom","Boolean","test","advanced","setAdvanced","customField","event","target","size","fullWidth","helperText","undefined","sx","flex","chip","spacing","minWidth","useFlexGap","direction","alignItems","flexWrap","variant","onClick","toLowerCase","title","color","onDelete","maxWidth","component","type","underline","open","alignSelf","in","unmountOnExit","fallback","onClose","onPicked","selector","picked"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;AAEA,SACEA,MAAM,EACNC,IAAI,EACJC,QAAQ,EACRC,IAAI,EACJC,KAAK,EACLC,SAAS,EACTC,OAAO,QACF,gBAAe;AACtB,SAASC,IAAI,EAAEC,QAAQ,EAAEC,QAAQ,QAA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AAMkC,WAAW,IAAI;;kCAE1E,KAAC1C;wBAAQ2C,OAAOlC,SAAS;kCACvB,cAAA,KAACd;4BACCgC,MAAK;4BACLnB,OAAOyB;4BACPO,SAAS/B,QAAQ,WAAW;4BAC5BmC,OAAOnC,QAAQ,YAAY;4BAC3BoC,UAAUpC,QAAQ,IAAMC,SAAS,MAAMoB;4BACvCC,IAAI;gCAAEe,UAAU;4BAAI;;;;;0BAI1B,KAACjD;gBACCkD,WAAU;gBACVC,MAAK;gBACLR,SAAQ;gBACRS,WAAU;gBACVR,SAAS,IAAMlB,YAAY,CAAC2B,OAAS,CAACA;gBACtCnB,IAAI;oBAAEoB,WAAW;gBAAa;0BAE7B7B,WAAW,yBAAyB;;0BAEvC,KAAC1B;gBAASwD,IAAI9B;gBAAU+B,aAAa;0BAClC7B;;YAEFT,wBACC,KAACb;gBAASoD,UAAU;0BAClB,cAAA,KAAClD;oBACCO,QAAQA;oBACRC,aAAaA;oBACb2C,SAAS,IAAMvC,WAAW;oBAC1BwC,UAAU,CAACC,UAAUC;wBACnBxC,eAAewC;wBACfnC,YAAY;wBACZb,SAAS+C;wBACTzC,WAAW;oBACb;;iBAGF;;;AAGV;AAEA,eAAeV,qBAAoB"}
@@ -33,6 +33,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
33
33
  import { ceilingedWindow, collectionCeiling, useFirestore, useFirestoreCollection, useHostResourceApi, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
34
34
  import { ACTION_TEST_RUN_API_ROUTE } from "../model/action-test-run.js";
35
35
  import { AutomationStepFields, defaultStep } from "./automation-step-fields.component.js";
36
+ import { ElementSelectorField } from "./element-selector-field.component.js";
36
37
  import { conditionRowsFromTrigger, conditionsFromRows, EMPTY_CONDITION_ROW, TriggerConditionRows } from "./automation-trigger-conditions.component.js";
37
38
  import HostRunHistoryCard from "./host-run-history-card.component.js";
38
39
  import { EDITOR_OPTION_CEILING, useAutomationStepPickers } from "./use-automation-step-pickers.js";
@@ -887,19 +888,17 @@ const CUSTOM_EVENT_VALUE = '__custom__';
887
888
  direction: "row",
888
889
  spacing: 1,
889
890
  children: [
890
- ELEMENT_SCOPED_SITE_EVENTS.includes((_ref12 = draft == null ? void 0 : draft.trigger.event) != null ? _ref12 : '') ? /*#__PURE__*/ _jsx(TextField, {
891
- label: "CSS selector",
892
- placeholder: "#pricing-table",
891
+ ELEMENT_SCOPED_SITE_EVENTS.includes((_ref12 = draft == null ? void 0 : draft.trigger.event) != null ? _ref12 : '') ? /*#__PURE__*/ _jsx(ElementSelectorField, {
892
+ label: "Element",
893
+ hostId: hostId,
894
+ // Open the page the trigger is limited to, when it names one.
895
+ initialPath: (draft == null ? void 0 : draft.trigger.pathPattern) && !draft.trigger.pathPattern.includes('*') ? draft.trigger.pathPattern : undefined,
893
896
  value: (_ref13 = draft == null ? void 0 : draft.trigger.selector) != null ? _ref13 : '',
894
- onChange: (event)=>patch((previous)=>_extends({}, previous, {
897
+ onChange: (selector)=>patch((previous)=>_extends({}, previous, {
895
898
  trigger: _extends({}, previous.trigger, {
896
- selector: event.target.value
899
+ selector
897
900
  })
898
- })),
899
- size: "small",
900
- sx: {
901
- flex: 1
902
- }
901
+ }))
903
902
  }) : null,
904
903
  [
905
904
  'scrollDepth',
@@ -1010,7 +1009,8 @@ const CUSTOM_EVENT_VALUE = '__custom__';
1010
1009
  replyContext: {
1011
1010
  event: draft == null ? void 0 : draft.trigger.event,
1012
1011
  afterWait: stepRunsAfterWait(draft == null ? void 0 : draft.steps, index)
1013
- }
1012
+ },
1013
+ siteHostId: hostId
1014
1014
  }, index)),
1015
1015
  /*#__PURE__*/ _jsx(Button, {
1016
1016
  size: "small",