@openpicker/sdk 0.2.1 → 0.2.3
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 +39 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -27,5 +27,44 @@ if (await op.isAvailable()) {
|
|
|
27
27
|
}
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Constrain the selector
|
|
31
|
+
|
|
32
|
+
Pass per-dimension rules into a pick (id / class / attribute / tag, each with an `allow` and an
|
|
33
|
+
`ignore` regex), lock the picker UI so the user can't loosen them, and/or require a unique match:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const { selector } = await op.pick({
|
|
37
|
+
url: "https://app.example.com",
|
|
38
|
+
selector: {
|
|
39
|
+
attr: { allow: "^data-step$" }, // only the data-step attribute
|
|
40
|
+
id: { enabled: false },
|
|
41
|
+
class: { enabled: false },
|
|
42
|
+
tag: { enabled: false },
|
|
43
|
+
},
|
|
44
|
+
lockSelectorSettings: true, // rule settings shown read-only
|
|
45
|
+
lockSelectorEdit: true, // selector field read-only
|
|
46
|
+
requireUniqueMatch: true, // confirm only when exactly one element matches
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
SDK rules compose with the user's own saved rules — each layer can only narrow. Since the user can
|
|
51
|
+
still hand-edit the selector unless you set `lockSelectorEdit`, validate the result against your
|
|
52
|
+
config with `matchesSelectorConfig`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { matchesSelectorConfig } from "@openpicker/sdk"
|
|
56
|
+
|
|
57
|
+
const config = { attr: { allow: "^data-step$" }, tag: { enabled: false } }
|
|
58
|
+
const { selector } = await op.pick({ url, selector: config })
|
|
59
|
+
if (!matchesSelectorConfig(selector, config)) {
|
|
60
|
+
// doesn't meet your requirement — ask the user to pick again
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
See [Configuring selectors](https://docs.openpicker.dev/guide/configuring-selectors) for the full
|
|
65
|
+
model.
|
|
66
|
+
|
|
67
|
+
## More
|
|
68
|
+
|
|
30
69
|
See the [protocol spec](https://github.com/usertour/openpicker/blob/main/PROTOCOL.md) for the
|
|
31
70
|
wire format, and the [main README](https://github.com/usertour/openpicker) for the full API.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpicker/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Open-source CSS element picker — SDK for invoking the openpicker browser extension.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Usertour (https://www.usertour.io)",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org/"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@openpicker/protocol": "^0.1.
|
|
46
|
+
"@openpicker/protocol": "^0.1.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.5.0",
|