@roughapp/feature 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/README.md +134 -0
- package/index.d.ts +1274 -0
- package/index.js +79 -0
- package/package.json +35 -0
- package/style.css +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# @roughapp/feature
|
|
2
|
+
|
|
3
|
+
Embeddable Web Components SDK for integrating Rough Features into a host
|
|
4
|
+
product. It ships compiled, minified ESM plus a stylesheet, and registers a set
|
|
5
|
+
of custom elements (including `<rough-surface>`).
|
|
6
|
+
|
|
7
|
+
> **Pre-1.0.** The API surface may change between minor versions during the
|
|
8
|
+
> `0.x` series. Pin an exact version if you need stability.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @roughapp/feature
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
This package targets **npm + a modern bundler** (Vite, Webpack, Rspack, …). It
|
|
17
|
+
is ESM-only and does not support direct `<script>`/CDN usage in this release.
|
|
18
|
+
|
|
19
|
+
`svelte`, `zod`, `capnweb`, `@andypf/json-viewer`, and
|
|
20
|
+
`@stayradiated/error-boundary` are installed automatically as runtime
|
|
21
|
+
dependencies — you do not need to add them yourself, though you can import `zod`
|
|
22
|
+
directly (see below).
|
|
23
|
+
|
|
24
|
+
## Import the stylesheet
|
|
25
|
+
|
|
26
|
+
The package does not inject a global CSS reset. Import the stylesheet once, near
|
|
27
|
+
your app entry, to get the Rough theme variables:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import '@roughapp/feature/style.css'
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Component styles are registered automatically by the custom elements at runtime.
|
|
34
|
+
|
|
35
|
+
## Recommended API
|
|
36
|
+
|
|
37
|
+
### Define a surface
|
|
38
|
+
|
|
39
|
+
A surface describes a place in your product where Rough features appear, plus
|
|
40
|
+
the tools the feature can call. Import `z` from `zod` directly for tool schemas:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { defineSurface, Query, Mutation, Subscription } from '@roughapp/feature'
|
|
44
|
+
import { z } from 'zod'
|
|
45
|
+
|
|
46
|
+
export const inboxSurface = defineSurface({
|
|
47
|
+
key: 'inbox',
|
|
48
|
+
name: 'Inbox',
|
|
49
|
+
description: 'The main message inbox.',
|
|
50
|
+
toolList: [
|
|
51
|
+
new Query({
|
|
52
|
+
id: 'listMessages',
|
|
53
|
+
name: 'List Messages',
|
|
54
|
+
description: 'List messages in the inbox.',
|
|
55
|
+
inputSchema: z.object({ limit: z.number().default(20) }),
|
|
56
|
+
outputSchema: z.array(z.object({ id: z.string(), subject: z.string() })),
|
|
57
|
+
outputSample: [{ id: 'msg_1', subject: 'Welcome' }],
|
|
58
|
+
implementation: async ({ limit }) => {
|
|
59
|
+
/* return messages */
|
|
60
|
+
return []
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
// Mutation and Subscription take the same options shape.
|
|
64
|
+
],
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`Query`, `Mutation`, and `Subscription` are re-exported from
|
|
69
|
+
`@roughapp/bridge` for convenience.
|
|
70
|
+
|
|
71
|
+
### Initialize the SDK
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { initRough } from '@roughapp/feature'
|
|
75
|
+
|
|
76
|
+
initRough({
|
|
77
|
+
projectId: 'proj_123',
|
|
78
|
+
fetchUserToken: async () => myAppSession.getRoughToken(),
|
|
79
|
+
// baseUrl is optional; defaults to the Rough production API.
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Render a surface
|
|
84
|
+
|
|
85
|
+
Use the `<rough-surface>` custom element, or the `RoughSurface` component
|
|
86
|
+
export. Set the `surface` property to a `defineSurface(...)` result:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import '@roughapp/feature'
|
|
90
|
+
|
|
91
|
+
const el = document.createElement('rough-surface')
|
|
92
|
+
el.surface = inboxSurface
|
|
93
|
+
document.querySelector('#rough-slot')?.append(el)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### List features and open the create flow
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { getRoughFeatures, openRoughCreate } from '@roughapp/feature'
|
|
100
|
+
|
|
101
|
+
// Subscribe to the published features for a surface.
|
|
102
|
+
const unsubscribe = getRoughFeatures(inboxSurface, (features) => {
|
|
103
|
+
console.log(features)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Open the "create a feature" modal for a surface.
|
|
107
|
+
openRoughCreate(inboxSurface, { projectId: 'proj_123' })
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Exports
|
|
111
|
+
|
|
112
|
+
Recommended, stable-ish customer API:
|
|
113
|
+
|
|
114
|
+
- `initRough`, `defineSurface` (+ `SurfaceDefinition` type)
|
|
115
|
+
- `getRoughFeatures`, `openRoughCreate`
|
|
116
|
+
- `RoughSurface` / `<rough-surface>`
|
|
117
|
+
- `Query`, `Mutation`, `Subscription` (re-exported from `@roughapp/bridge`)
|
|
118
|
+
|
|
119
|
+
Advanced / incidental exports — these exist but are **not** intended as stable
|
|
120
|
+
customer dependencies during the pre-1.0 series:
|
|
121
|
+
|
|
122
|
+
- Custom-element components: `RoughCreateModal` (`<rough-create-modal>`),
|
|
123
|
+
`RoughEditButton` (`<rough-edit-button>`), `RoughFeature` (`<rough-feature>`)
|
|
124
|
+
(the `<rough-edit-modal>` element registers transitively).
|
|
125
|
+
- UI building blocks: `PrimaryButton`, `SecondaryButton`, `ResizeHandle`,
|
|
126
|
+
`SpriteBuildMenu`, `SpriteFrame`.
|
|
127
|
+
- `registerSurfaceEntry`.
|
|
128
|
+
- Types: `Sprite`, `SpriteBuild`, `JsonValue`, `SpriteFrameDatastore`,
|
|
129
|
+
`SpriteFrameDatastoreContext`.
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
`UNLICENSED`. This package is publicly installable but is not open source; use
|
|
134
|
+
is governed by your Rough customer terms.
|