@plitzi/sdk-elements 0.38.13 → 0.38.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,268 @@
1
1
  # @plitzi/sdk-elements
2
2
 
3
+ ## 0.38.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 6cdd5cf: ## Security
8
+
9
+ - **A write another site caused is refused, cookie or none** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): the page
10
+ server guarded nothing it answers past `/auth` — a server action (`/_action`), a realtime publish, a space's `/fn/`
11
+ route, its runtime's endpoints, the deployment's own `data` stages, the adapter-only `loginPath`, `logoutPath` and
12
+ `exchangePath`. A plain `text/plain` POST from any page open in the same browser ran them, with the visitor's session
13
+ cookie when there was one (`SameSite=None` off this machine) and, in a project nobody signs in to, as whoever holds
14
+ the server's own credentials. Every unsafe request a browser says another site caused (`Sec-Fetch-Site: cross-site`,
15
+ or a foreign `Origin`) is now refused `403 reason: 'foreign'`, saying how to allow it: `crossSiteWrites.origins`
16
+ (with `auth`, `identity.platformOrigins` too) and `crossSiteWrites.paths` for a form other sites post to by design.
17
+ `Authorization`, and callers that are not browsers — webhooks, scripts — pass as before. One rule for this and the
18
+ sign-in check (`crossSiteRequest`, `csrf.ts`). A self-hosted runtime's endpoints now sit where the platform forwards a
19
+ space's — after the auth chain and this guard (`data`, was `preAuth`).
20
+
21
+ ## Testing
22
+ - **`page check` and `page shot` anywhere the project is served** (`@plitzi/cli`): `--url <origin>` for a second server
23
+ of it, staging or a deploy, instead of `npm start`'s port; `page check --space <module>` holds the pages to that space
24
+ instead of the project's — an agent's page — authored with `authorIsolated`.
25
+ - **A route with a query is checked as its page** (`@plitzi/cli`): `page check "/?v=2"` matched the query as part of
26
+ the path, found no page, and checked the space's "not found" page in its place.
27
+
28
+ - **What an element that chooses its children draws is checked** (`@plitzi/sdk-authoring`, `@plitzi/cli`): with
29
+ `choosesChildren`, the page checks owed none of its children — and checked none of them either: a dashboard drawing
30
+ three panels reported `checked: 1`. Each child it may draw, and what is inside one under no condition of its own,
31
+ now carries `shownWith` (the child it comes with) on its handle: once that child is on screen it and everything
32
+ named in it are owed like the rest of the page, and `checked` counts them. `onScreenIfChosen(handles, page)` lists
33
+ them.
34
+ - **A page that met a server error is looked at once more** (`@plitzi/cli`): `page check` and `verify` failed a page
35
+ for a `500` from somebody else's service having a bad second (`/fn/<space>/weather`), and passed on the next run with
36
+ nothing changed. A page whose requests got a `5xx` is checked again once; its report is the second look, and says
37
+ what failed the first time (`retriedAfter`). A `4xx` fails the same way twice, and is never retried.
38
+
39
+ ## Plugins
40
+ - **`useNotify`** (`@plitzi/plitzi-sdk`): a plugin shows the page's notifications — `notify('Deleted 79 recordings', {
41
+ appearance: 'danger' })` — the same toasts an `addNotification` step shows, in the space's theme and `notifications`
42
+ look, with no trigger, flow or `window` event of the space's to wire. The step's vocabulary (`NOTIFICATION_PLACEMENTS`,
43
+ `NOTIFICATION_APPEARANCES`, `NOTIFICATION_DEFAULTS`) is one list in `@plitzi/sdk-shared`, read by both.
44
+ - **`appearance: 'danger'` looks like one** (`@plitzi/plitzi-sdk`): it reached the toast library as a type it does not
45
+ know, so a danger notification showed neither the error icon nor the colour `notifications.danger` sets.
46
+ A value a notification does not take — from a flow, or a plugin in plain JavaScript — is set aside by name and said
47
+ in the console, rather than shown as the default in silence (`readNotificationOptions`, `@plitzi/sdk-shared`).
48
+ - **`useServerAction`** (`@plitzi/plitzi-sdk`, `@plitzi/sdk-authoring`, `@plitzi/sdk-interactions`,
49
+ `@plitzi/sdk-server`): a plugin runs one of the space's server actions, awaited —
50
+ `useServerAction<typeof habitDone>('habits-done')({ id })` answers `{ ok, output }` or `{ ok: false, reason, error }`
51
+ — through the `runServerAction` step itself: the same access, refusals, session handling and dev-tools entry.
52
+ `defineAction` keeps the literal types of its `call` way in, so the input is typed by the fields it declares (the
53
+ required ones required); `taskAction` types both ends from the task's `run`, and `FunctionTask<T, R>` takes what
54
+ `run` answers. `CallInputOf` / `CallOutputOf` read them. One operation is one action, never a `case` in one route.
55
+ What a run answers is typed (`ServerActionStatus`): a status the server never uses reads as a run that did not
56
+ complete, never as one that did.
57
+ The key those types ride under (`CALL_TYPES`) is exported, by `@plitzi/sdk-shared` and `@plitzi/sdk-authoring` with
58
+ `TypedActionEntry`, `CallInputOf` and `CallOutputOf`: a package that emits declarations could not write the type of an
59
+ action it exports (`TS4023` on every `export const actions = [defineAction(…)]`).
60
+ - **A plugin is drawn on the server first** (docs): a preference per device belongs in kept state (`keepState`,
61
+ `paintedState`) as a bound prop, never read from `localStorage` while rendering — React discards the whole tree on the
62
+ mismatch, and only in the browser of whoever saved something. `@plitzi/plitzi-ui` is not the page's: a plugin
63
+ importing it bundles its own copy, with its own contexts and its own look. The authoring skill's `plugin-reach.md`
64
+ says what a plugin says and to whom: a notification, another element (an event and the space's flow), a server
65
+ action, shared state, other pages.
66
+
67
+ ## Realtime
68
+ - **A channel that retains** (`@plitzi/sdk-shared`, `@plitzi/sdk-server`, `@plitzi/sdk-elements`): declared
69
+ `retain: true` (with `publish: 'server'`, which authoring requires), the server keeps the latest message of each type
70
+ on a topic — said by `ctx.publish` or a flow's `realtime.publish` — and hands them to every page that joins, marked
71
+ `retained`. A page reads them as `<channel>.retained.<type>`, a plugin as `useChannel(topic).retained`, the newest of
72
+ a type holding whichever order they arrive in; `null` forgets a type. Kept in the store the actions' `kv` uses (beside
73
+ the grants, by compare-and-swap), so every replica hands out the same; a topic keeps at most 64 types and 512 KB, and
74
+ a publish past that is refused before anything is sent. State every screen shares is one publish and one binding —
75
+ no kv key, initial read or copy in `state` of the project's own. The fleet store `realtime.grants` is now
76
+ `realtime.kv`.
77
+ - **The MCP writes every field a channel takes** (`@plitzi/sdk-mcp`): `patchSettings`'s channel had no `grant` — which
78
+ the guide taught — nor `retain` or the limits, so an agent could not declare a private channel at all. All are there
79
+ now, and the guide says what `retain` is for and that `channel_<id>.retained` holds it.
80
+
81
+ ## Authoring
82
+ - **`plitzi explain` knows every `@plitzi` package installed** (`@plitzi/cli`): a name that was not
83
+ `@plitzi/sdk-authoring`'s (`createServer`, `createJsonAdapters`, `useChannel`) was answered as the project's own code,
84
+ to `grep` in `src/`. It is read from the published types of every one installed, through their re-exports and entry
85
+ points (`@plitzi/sdk-server/handlers`), and a name two packages export — `createServer` is sdk-server's and sdk-mcp's
86
+ — is answered with both.
87
+
88
+ - **A space module somebody else wrote, authored where it reaches nothing** (`@plitzi/sdk-authoring`):
89
+ `authorIsolated(file, { timeoutMs })` of `@plitzi/sdk-authoring/node` runs `authorSpace` on it in a process Node's
90
+ permission model holds to reading the module's folder and its packages — no file written, no process started, no
91
+ variable of the caller's environment — kills one that runs too long, and validates what it answers again, so a forged
92
+ answer gains nothing. A refusal comes back as `authorSpace` says it, with the problems as data.
93
+ - **Pages an agent writes, served** (`@plitzi/sdk-server`): `createAuthoringHost({ dir, frameAncestors })` serves each
94
+ space it is handed at an address of its own (`put(space, { id }) → /?__pt=<id>`) as a draft of its one space, kept in
95
+ `dir` across restarts; `drop(id)` forgets one, and anything else answers `404` saying where the pages are.
96
+ - **A space is chosen by host or credential** (`@plitzi/sdk-server`, docs): `getSpaceDeployment` is asked on every
97
+ request, and what a page fetches after it carries nothing of its address but the host — a space chosen by the page's
98
+ query or path lost everything it asked for, and `/_plitzi/space/<hash>.json` answered a bare `404`. The contract and
99
+ the README say so (the README offered "by path prefix"), and that `404` says why.
100
+
101
+ - **`plitzi explain on` says how to read what a trigger carries** (`@plitzi/sdk-authoring`): its doc sat above a
102
+ helper, so `explain` printed only the signature. It now leads with `[named('picked', on('onPick')), …('{{ picked.seat
103
+ }}')]`, and the CLI skill's plugin section says the same.
104
+
105
+ - Updated dependencies [6cdd5cf]
106
+ - @plitzi/sdk-auth@0.38.15
107
+ - @plitzi/sdk-event-bridge@0.38.15
108
+ - @plitzi/sdk-interactions@0.38.15
109
+ - @plitzi/sdk-navigation@0.38.15
110
+ - @plitzi/sdk-schema@0.38.15
111
+ - @plitzi/sdk-shared@0.38.15
112
+
113
+ ## 0.38.14
114
+
115
+ ### Patch Changes
116
+
117
+ - 493955a: ## SDK
118
+
119
+ - **An embedded space leaves the page's theme alone** (`@plitzi/plitzi-sdk`, `@plitzi/plitzi-builder`): plitzi-ui's
120
+ `Provider` stamps `dark` on `<html>` by default — and, being `light`, takes it off — so every space mounted with
121
+ `themeScope: 'container'` turned the page around it light, and nothing put it back. The SDK and the builder now leave
122
+ the class to their own theme provider (`applyColorModeClass={false}`).
123
+ - **A space inside a space** (`@plitzi/plitzi-sdk`, `@plitzi/sdk-shared`): one drawn inside another — the `plitziSdk`
124
+ element, a plugin rendering one, the builder's canvas — knows it (`render.enclosed`). It is `container` unless it
125
+ says otherwise, wears its theme on its own root and starts from the page's when its own is `system`, keeps its
126
+ stylesheet to its own root (`@scope` — its `:root` palette and `.dark` rules repainted the outer page, its
127
+ `.plitzi-sdk` rule restyled the outer root), writes no `<title>` (`ownsHead`) and no `theme` cookie.
128
+ - **The `plitziSdk` element draws** (`@plitzi/plitzi-sdk`): it rendered in `widget` mode with no page to show, so it
129
+ drew nothing. A widget with no `currentPageId` now shows the page its home address would. And it takes a space's
130
+ documents as well as a key: `offlineData`, bound whole (an `apiContainer`'s answer, a runtime's route, what
131
+ `plitzi_render` returns) or as `offlineData.schema` and `offlineData.style` from two elements — waiting, without an
132
+ error, for the half that has not answered; one that cannot be drawn is said why, in the console and on the canvas.
133
+ - **`<PlitziSdk>` inside a plugin draws** (`@plitzi/plitzi-sdk`): it mounted a router of its own inside the page's, and
134
+ React Router refused it — `routing: 'memory'` or not. A space inside another is a widget: `raw` becomes `widget`
135
+ there, one page and no router (a frame of its own, `iframe` or `shadow`, is left as asked).
136
+ - **A space inside another is as tall as what it holds** (`@plitzi/plitzi-sdk`): its root was `min-h-screen`, as a
137
+ space that IS the page is, so a card of three lines drawn in a panel took the window's height.
138
+ - **`<PlitziSdk.Plugin component>` takes a component with its own props** (`@plitzi/plitzi-sdk`), as `render()`'s
139
+ plugins do: typed `ComponentPluginFC`, it refused any component that read its attributes.
140
+ - **An edited page keeps its address in step** (`@plitzi/plitzi-sdk`): the routes are built from the pages' own
141
+ elements, and those were read again only when the list of pages changed — an edit to one page (its slug, its flag)
142
+ leaves that list the same, and the routes kept its old address until something else rebuilt them.
143
+ - **Packages declare only what they use** (`@plitzi/sdk-dev-tools`, `@plitzi/sdk-shared`): `@plitzi/sdk-plugins`, which
144
+ the dev tools no longer import, and `terser`, which no build here runs, are no longer dependencies.
145
+ - **An edited page keeps its route up to date** (`@plitzi/plitzi-sdk`): the routes are built from the pages' own
146
+ elements, which were read again only when the list of pages changed — an edit to one page (its slug, its flag) left
147
+ the list the same and the route at the old address. They follow every edit to a page now, and stay the same object
148
+ while no page changes.
149
+ - **`@plitzi/sdk-dev-tools` no longer depends on `@plitzi/sdk-plugins`**, which nothing in it imports.
150
+ - **A dropdown's menu opens inside a card that lifts or clips** (`@plitzi/sdk-elements`, `@plitzi/sdk-shared`): drawn
151
+ inside the dropdown, an ancestor with a `transform` — a card lifting on hover — made itself the containing block of
152
+ the menu's `position: fixed`, and one with `overflow: hidden` cut it off: the menu opened and nobody saw it. The open
153
+ menu and its backdrop are drawn at the space's root (`spaceRootOf`, `@plitzi/sdk-shared/helpers/spaceRoot`); a
154
+ style written for the popup by an ancestor's selector no longer reaches it — its own classes do.
155
+ - **A copy button says when it could not copy** (`@plitzi/sdk-elements`, `@plitzi/sdk-shared`,
156
+ `@plitzi/sdk-interactions`, `@plitzi/sdk-variables`, `@plitzi/sdk-dev-tools`): a page not served over https has no
157
+ clipboard — a phone opening a development server by its address — and a code block's "Copy" threw there. It reads
158
+ "Not copied", and says why. `clipboardWriter` and `copyText` (`@plitzi/sdk-shared/helpers/clipboard`) are the one
159
+ check, the `copyToClipboard` step's too.
160
+
161
+ ## Authoring
162
+ - **`plitziSdk` is authored like any element** (`@plitzi/sdk-authoring`, `@plitzi/sdk-elements`): its declaration moved
163
+ to `@plitzi/sdk-elements` beside the others, so it has a factory — `plitziSdk({ id, bind: { offlineData: 'view.data'
164
+ } })` —, its attributes typed, and `plitzi explain` knows it.
165
+ - **A binding may write part of an attribute** (`@plitzi/sdk-authoring`): `offlineData.schema` writes into
166
+ `offlineData`, as the runtime always did; authoring refused it as an attribute nothing reads.
167
+ - **`choosesChildren`** (`@plitzi/sdk-shared`, `@plitzi/sdk-authoring`): a plugin that shows only some of the elements
168
+ put inside it — a dashboard's panels, a wizard's step — says so in its declaration, and the page checks owe none of
169
+ them on screen; what it draws is still read by the checks of the whole page (images, sideways scroll, legibility).
170
+ `verify` was red on every such page.
171
+
172
+ - **A page says how the document scrolls** (`@plitzi/sdk-elements`, `@plitzi/sdk-authoring`, `@plitzi/sdk-mcp`):
173
+ `documentScroll: 'locked'` holds the document still while the page is open — a dashboard or a board used with a
174
+ finger, where the whole page was dragged and bounced back though nothing in it scrolls — and `'noBounce'` keeps the
175
+ scroll without the rubber band or pull-to-refresh. The page draws the rule itself, so it is in the server's HTML and
176
+ leaves with the page; never inside a widget, a space drawn in another, or the builder's canvas. A Settings select,
177
+ `PageSpec.documentScroll`, `upsertPage`'s `documentScroll` (`null` undoes it) and the page read; an unknown value is
178
+ refused (`attribute-value`). `upsertPage` is now held to the lint of the page it writes, as element writes are.
179
+
180
+ ## MCP
181
+ - **`@plitzi/sdk-mcp/render`** (`@plitzi/sdk-mcp`): `plitzi_render`'s widget render on its own — no MCP server, no SSR,
182
+ no OAuth — for a project whose own agent draws in its own pages: `render`, `renderWidgetShape` to declare it as a
183
+ tool, `renderGuideText` for the agent. `base`, the style of the project's space, brings its tokens, classes and fonts
184
+ to the widget.
185
+
186
+ ## Server
187
+ - **`publicUrl` says where people reach the server** (`@plitzi/sdk-server`): it was `http://127.0.0.1:<port>` whatever
188
+ the server was. It is `https` once `serverOptions.tls` gives it a certificate, and this machine's network address
189
+ with `HOST` open to the network (what a tablet opens, what an OAuth provider sends it back to); `PUBLIC_URL` still
190
+ wins. The network addresses it prints say `https` too.
191
+ - **A server serving TLS reaches itself** (`@plitzi/sdk-server`): with a local certificate (mkcert) Node trusts nothing
192
+ the browsers were told to, so a runtime calling its own MCP failed. Its requests to its own address now connect to its
193
+ listener and are taken when it presents exactly its certificate (`reachOwnServer`, exported from `/runtime`).
194
+ - **A runtime reads compressed answers again** (`@plitzi/sdk-server`): the dispatcher `reachOwnServer` (and the
195
+ platform's `reachSpaceInside`) installs reached every other host with an undici connector that offers HTTP/2, and an
196
+ answer that came back over h2 reached Node's `fetch` without its `content-encoding` — every API that compresses read
197
+ as Brotli bytes. Other hosts are reached over HTTP/1.1 now, as Node's own `fetch` reaches them.
198
+ - **A project's server serves HTTPS from `.env`** (`@plitzi/sdk-server`, `@plitzi/sdk-shared`): `TLS_CERT` and
199
+ `TLS_KEY`, the certificate's and the key's paths — what `plitzi cert` writes — with no code of the project's;
200
+ `serverOptions.tls` still wins. A network address the certificate does not name is said at boot, the machine's
201
+ `.local` name is printed among the addresses when it is named, and a server on loopback alone says how to open it to
202
+ the network.
203
+ - **A session survives a phone on the Wi-Fi** (`@plitzi/sdk-server`): a private network address (`192.168.…`, `10.…`,
204
+ Tailscale's `100.64/10`, IPv6 unique- and link-local) and a machine's mDNS name (`studio.local`) get the local
205
+ cookie profile — `SameSite=Lax`, no `Secure`, no `Domain`. They got `SameSite=None; Secure`, which a browser drops
206
+ over http: nobody could sign in from a tablet. A deployment's own `.local` sub-domains (`app.example.local`) keep the
207
+ strict profile.
208
+ - **Hiding the dev tools on a server over HTTPS hydrates** (`@plitzi/sdk-server`): a server with a certificate speaks
209
+ HTTP/2, which sends no `Host` — only `:authority` — and the cookies named for the origin's port (the dev tools'
210
+ `plitzi_debug_<port>`, forced flags, painted state) were looked for without it. Shift+F12 hid the dev tools in the
211
+ browser, the server rendered them back, and the page failed to hydrate. Every one is read off `requestAuthority`.
212
+ - **A rebuild of plugins says it finished** (`@plitzi/sdk-server`): bundles removed under a running server (`tmp/`
213
+ deleted) were each a warning, "rebuilding…", and their "ready" at a level a project's terminal does not show. It is
214
+ one episode now: said when noticed, and again when the last is built — how many, how long, which failed.
215
+ - **`tmp/dev-server.json` records the scheme** (`@plitzi/sdk-server`): `url` is `https` with a certificate, and the
216
+ file adds the network addresses and the `publicUrl`.
217
+ - **`public/` is asked about every time** (`@plitzi/sdk-server`): it was cached for an hour — a `.js` or `.css` in it
218
+ for a year, `immutable` — so a file a project rewrites while it runs arrived stale. It is `no-cache` now, answered
219
+ `304` by its `ETag` while unchanged; `immutable` stays for what is versioned (the SDK, the plugins).
220
+
221
+ ## CLI
222
+ - **`check`, `shot`, `verify` and `visual` find a server on HTTPS** (`@plitzi/cli`): they rebuilt
223
+ `http://127.0.0.1:<port>`, so a project serving a certificate had no page checked. They read the URL `npm start`
224
+ recorded, and take a local certificate on this machine only. A project's `playwright.config.ts` comes from
225
+ `plitzi upgrade`.
226
+ - **`verify` runs the project's tests** (`@plitzi/cli`): a step `test`, after the lint, when `package.json` has a
227
+ `test` script.
228
+ - **`tsconfig.json` is the project's** (`@plitzi/cli`): the compiler options moved to `plitzi/tsconfig.base.json`, which
229
+ the CLI keeps up and `tsconfig.json` extends — so a folder of the project's own (`scripts/`, `tools/`) goes in its
230
+ `include` without changing a file of the CLI's. `plitzi doctor --fix` makes an older `tsconfig.json` extend it,
231
+ keeping only the options the project changed.
232
+ - **`doctor --fix` and `upgrade` write as the project's Prettier does** (`@plitzi/cli`): a repaired `tsconfig.json` or
233
+ `package.json` left `verify`'s format step red.
234
+ - **`upgrade` renames `usePlitziServiceContext`** (`@plitzi/cli`): with `PlitziServiceProvider` and
235
+ `PlitziServiceContextValue`, renamed in 0.38.12 with no alias — import, use and the module path that named it.
236
+ - **`skills update` compares every file** (`@plitzi/cli`): only `SKILL.md` was, so a change in a reference alone was
237
+ "up to date".
238
+ - **`NOTES.md`, the project's notes for agents** (`@plitzi/cli`): `AGENTS.md` and `CLAUDE.md` are the CLI's and
239
+ `upgrade` replaces them, so what a project's own sessions had to know had nowhere to live. `CLAUDE.md` imports
240
+ `NOTES.md`, `AGENTS.md` sends every agent to it, and nothing the CLI does touches it; `doctor --fix` writes one for
241
+ a project that has none.
242
+
243
+ - **`start:dev-inspect`** (`@plitzi/cli`): a server project's `start:dev` with Node's inspector open on
244
+ 127.0.0.1:9229, so a debugger (VS Code, `chrome://inspect`) attaches to the server, and again after each restart.
245
+ `plitzi upgrade` adds it; `plitzi runtime add` has it restart on the runtime too.
246
+ - **`plitzi cert`** (`@plitzi/cli`): HTTPS while developing, for a phone or a tablet on the Wi-Fi — over http its
247
+ browser gives a page no microphone, camera or clipboard. A certificate from mkcert's local authority for this machine,
248
+ its network addresses and its `.local` name, in `tmp/tls/`, named in `.env`; what to install on the phone, said.
249
+ - **A browser project opens to the network** (`@plitzi/cli`): its `vite.config.ts` reads `HOST`, `TLS_CERT` and
250
+ `TLS_KEY` from `.env`, as a server project does, and writes `tmp/dev-server.json` — the port Vite took and the scheme
251
+ — so `page check`, `page shot` and `visual` find it on another port or over HTTPS. `plitzi upgrade` brings it.
252
+
253
+ ## Docs
254
+ - **Two plugins share through `state`** (`@plitzi/sdk-authoring` skill): each plugin is a bundle of its own, so a module
255
+ both import is two copies, and what one keeps there the other never sees.
256
+ - **`verify --help`** names the project's tests among its steps.
257
+
258
+ - Updated dependencies [493955a]
259
+ - @plitzi/sdk-auth@0.38.14
260
+ - @plitzi/sdk-event-bridge@0.38.14
261
+ - @plitzi/sdk-interactions@0.38.14
262
+ - @plitzi/sdk-navigation@0.38.14
263
+ - @plitzi/sdk-schema@0.38.14
264
+ - @plitzi/sdk-shared@0.38.14
265
+
3
266
  ## 0.38.13
4
267
 
5
268
  ### Patch Changes
@@ -1,34 +1,40 @@
1
1
  import { useCallback as e, useEffect as t, useState as n } from "react";
2
2
  import { jsx as r, jsxs as i } from "react/jsx-runtime";
3
3
  import a from "clsx";
4
+ import { NOT_COPIED_REASON as o, copyText as s } from "@plitzi/sdk-shared/helpers/clipboard";
4
5
  //#region src/components/MarkdownDocument/components/CodeBlock/CodeBlock.tsx
5
- var o = 2e3, s = ({ language: s, code: c, classNames: l, children: u }) => {
6
- let [d, f] = n(!1);
6
+ var c = 2e3, l = {
7
+ idle: "Copy",
8
+ copied: "Copied",
9
+ refused: "Not copied"
10
+ }, u = ({ language: u, code: d, classNames: f, children: p }) => {
11
+ let [m, h] = n("idle");
7
12
  t(() => {
8
- if (!d) return;
9
- let e = setTimeout(() => f(!1), o);
13
+ if (m === "idle") return;
14
+ let e = setTimeout(() => h("idle"), c);
10
15
  return () => clearTimeout(e);
16
+ }, [m]);
17
+ let g = e(() => {
18
+ s(d).then((e) => h(e ? "copied" : "refused"));
11
19
  }, [d]);
12
- let p = e(() => {
13
- navigator.clipboard.writeText(c).then(() => f(!0));
14
- }, [c]);
15
20
  return /* @__PURE__ */ i("div", {
16
- className: a("markdown-code", l.codeBlockFrame),
17
- "data-language": s,
21
+ className: a("markdown-code", f.codeBlockFrame),
22
+ "data-language": u,
18
23
  children: [/* @__PURE__ */ i("div", {
19
- className: a("markdown-code-header", l.codeBlockHeader),
24
+ className: a("markdown-code-header", f.codeBlockHeader),
20
25
  children: [/* @__PURE__ */ r("span", {
21
- className: a("markdown-code-language", l.codeBlockLanguage),
22
- children: s ?? "text"
26
+ className: a("markdown-code-language", f.codeBlockLanguage),
27
+ children: u ?? "text"
23
28
  }), /* @__PURE__ */ r("button", {
24
29
  type: "button",
25
- className: a("markdown-code-copy", l.codeBlockCopy),
26
- onClick: p,
30
+ className: a("markdown-code-copy", f.codeBlockCopy),
31
+ onClick: g,
27
32
  "aria-live": "polite",
28
- children: d ? "Copied" : "Copy"
33
+ title: m === "refused" ? o : void 0,
34
+ children: l[m]
29
35
  })]
30
- }), u]
36
+ }), p]
31
37
  });
32
38
  };
33
39
  //#endregion
34
- export { s as default };
40
+ export { u as default };
@@ -7,33 +7,48 @@ var a = ({ spaceKey: a = "", environment: o = "main", onUpdate: s }) => {
7
7
  let c = e(s);
8
8
  return /* @__PURE__ */ n("div", {
9
9
  className: "flex flex-col gap-4 py-2",
10
- children: [/* @__PURE__ */ t(r, {
11
- value: a,
12
- label: "Space Key",
13
- onChange: c.text("spaceKey")
14
- }), /* @__PURE__ */ n(i, {
15
- value: o,
16
- label: "Environment",
17
- onChange: c.text("environment"),
18
- children: [
19
- /* @__PURE__ */ t("option", {
20
- value: "main",
21
- children: "Main"
22
- }),
23
- /* @__PURE__ */ t("option", {
24
- value: "development",
25
- children: "Development"
26
- }),
27
- /* @__PURE__ */ t("option", {
28
- value: "staging",
29
- children: "Staging"
30
- }),
31
- /* @__PURE__ */ t("option", {
32
- value: "production",
33
- children: "Production"
34
- })
35
- ]
36
- })]
10
+ children: [
11
+ /* @__PURE__ */ t(r, {
12
+ value: a,
13
+ label: "Space Key",
14
+ onChange: c.text("spaceKey")
15
+ }),
16
+ /* @__PURE__ */ n(i, {
17
+ value: o,
18
+ label: "Environment",
19
+ onChange: c.text("environment"),
20
+ children: [
21
+ /* @__PURE__ */ t("option", {
22
+ value: "main",
23
+ children: "Main"
24
+ }),
25
+ /* @__PURE__ */ t("option", {
26
+ value: "development",
27
+ children: "Development"
28
+ }),
29
+ /* @__PURE__ */ t("option", {
30
+ value: "staging",
31
+ children: "Staging"
32
+ }),
33
+ /* @__PURE__ */ t("option", {
34
+ value: "production",
35
+ children: "Production"
36
+ })
37
+ ]
38
+ }),
39
+ /* @__PURE__ */ n("p", {
40
+ className: "text-xs",
41
+ children: [
42
+ "Or bind ",
43
+ /* @__PURE__ */ t("code", { children: "offlineData" }),
44
+ " to a space's documents — an API's answer, a runtime's route — or",
45
+ /* @__PURE__ */ t("code", { children: "offlineData.schema" }),
46
+ " and ",
47
+ /* @__PURE__ */ t("code", { children: "offlineData.style" }),
48
+ " from two elements, to draw it with no backend; the key is then not read."
49
+ ]
50
+ })
51
+ ]
37
52
  });
38
53
  };
39
54
  //#endregion
@@ -0,0 +1,39 @@
1
+ import { Environment, OfflineDataRaw } from '@plitzi/sdk-shared';
2
+ /** What this element can be authored with. */
3
+ export type PlitziSdkAttributes = {
4
+ /** The space drawn, fetched by its key. */
5
+ spaceKey?: string;
6
+ environment?: Environment;
7
+ /**
8
+ * The space drawn from its documents instead — `schema` and `style` with its compiled `cache`, what `plitzi_render`
9
+ * answers — with no backend behind it: UI generated on the fly, a preview. Usually bound: whole, to an
10
+ * `apiContainer`'s answer or a runtime's route, or `offlineData.schema` and `offlineData.style` from two elements.
11
+ * With it, `spaceKey` is not read.
12
+ */
13
+ offlineData?: OfflineDataRaw;
14
+ };
15
+ declare const declaration: import('@plitzi/sdk-shared/authoring/declare').DeclaredElement<{
16
+ readonly type: "plitziSdk";
17
+ readonly content: {
18
+ readonly attributes: {
19
+ readonly spaceKey: "";
20
+ readonly environment: "main";
21
+ };
22
+ readonly definition: {
23
+ readonly label: "Plitzi Sdk";
24
+ readonly description: "Another space drawn inside this one, as a widget — its home page, no router of its own: by its key, or from its documents (`offlineData`), bound to UI generated on the fly.";
25
+ };
26
+ readonly market: {
27
+ readonly category: "advanced";
28
+ readonly icon: "https://cdn.plitzi.com/resources/img/favicon.svg";
29
+ };
30
+ readonly defaultStyle: {
31
+ readonly style: {
32
+ readonly base: {
33
+ readonly default: {};
34
+ };
35
+ };
36
+ };
37
+ };
38
+ }, PlitziSdkAttributes>;
39
+ export default declaration;
@@ -0,0 +1,22 @@
1
+ import { elementDeclaration as e } from "@plitzi/sdk-shared/authoring/declare";
2
+ //#region src/elements/advanced/PlitziSdk/declaration.ts
3
+ var t = e()({
4
+ type: "plitziSdk",
5
+ content: {
6
+ attributes: {
7
+ spaceKey: "",
8
+ environment: "main"
9
+ },
10
+ definition: {
11
+ label: "Plitzi Sdk",
12
+ description: "Another space drawn inside this one, as a widget — its home page, no router of its own: by its key, or from its documents (`offlineData`), bound to UI generated on the fly."
13
+ },
14
+ market: {
15
+ category: "advanced",
16
+ icon: "https://cdn.plitzi.com/resources/img/favicon.svg"
17
+ },
18
+ defaultStyle: { style: { base: { default: {} } } }
19
+ }
20
+ });
21
+ //#endregion
22
+ export { t as default };
@@ -12,7 +12,7 @@ export type DropdownProps = {
12
12
  containerLeftOffset?: number;
13
13
  disabled?: boolean;
14
14
  };
15
- declare const Dropdown: ({ ref, children, className, popupPlacement, openPopup, backgroundDisabled, closeOnClickBackground, closeOnClickPopup, containerTopOffset, containerLeftOffset, disabled }: DropdownProps) => import('react').JSX.Element;
15
+ declare const Dropdown: ({ ref: refProp, children, className, popupPlacement, openPopup, backgroundDisabled, closeOnClickBackground, closeOnClickPopup, containerTopOffset, containerLeftOffset, disabled }: DropdownProps) => import('react').JSX.Element;
16
16
  declare const _default: {
17
17
  (props: import('../../../Element/hocs/withElement').WithElementProps<DropdownProps>): import('react').JSX.Element;
18
18
  displayName: string;
@@ -4,64 +4,78 @@ import { RootElement as n } from "../../../Element/RootElement.mjs";
4
4
  import r from "./DropdownContext.mjs";
5
5
  import i from "./useDropdown.mjs";
6
6
  import a from "./useDropdownTrigger.mjs";
7
- import { useCallback as o, useMemo as s, useRef as c } from "react";
8
- import l from "@plitzi/sdk-shared/hooks/usePlitzi";
9
- import { jsx as u, jsxs as d } from "react/jsx-runtime";
10
- import f from "clsx";
7
+ import { useCallback as o, useLayoutEffect as s, useMemo as c, useRef as l, useState as u } from "react";
8
+ import d from "@plitzi/sdk-shared/hooks/usePlitzi";
9
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
10
+ import m from "clsx";
11
+ import { createPortal as h } from "react-dom";
12
+ import { spaceRootOf as g } from "@plitzi/sdk-shared/helpers/spaceRoot";
11
13
  //#region src/elements/basic/Dropdown/Dropdown.tsx
12
- var p = ({ ref: e, children: p, className: m = "", popupPlacement: h = "bottom", openPopup: g = !1, backgroundDisabled: _ = !1, closeOnClickBackground: v = !0, closeOnClickPopup: y = !0, containerTopOffset: b = 5, containerLeftOffset: x = 5, disabled: S = !1 }) => {
13
- let { setElementState: C, definition: { styleSelectors: w } } = t(), { settings: { previewMode: T }, utils: { getWindow: E } } = l(), D = c(null), O = c(null), k = s(() => E(), [E]), A = o((e) => {
14
- v && (e.stopPropagation(), e.preventDefault(), C((e) => ({
14
+ var _ = ({ ref: e, children: _, className: v = "", popupPlacement: y = "bottom", openPopup: b = !1, backgroundDisabled: x = !1, closeOnClickBackground: S = !0, closeOnClickPopup: C = !0, containerTopOffset: w = 5, containerLeftOffset: T = 5, disabled: E = !1 }) => {
15
+ let { setElementState: D, definition: { styleSelectors: O } } = t(), { settings: { previewMode: k }, utils: { getWindow: A } } = d(), j = l(null), M = e ?? j, N = l(null), P = l(null), F = c(() => A(), [A]), I = o((e) => {
16
+ S && (e.stopPropagation(), e.preventDefault(), D((e) => ({
15
17
  ...e,
16
18
  openPopup: !1
17
19
  })));
18
- }, [v, C]), j = o((e) => {
19
- C((t) => ({
20
+ }, [S, D]), L = o((e) => {
21
+ D((t) => ({
20
22
  ...t,
21
23
  openPopup: e
22
24
  }));
23
- }, [C]), [, , M, N, , P] = i({
24
- ref: e,
25
- popupRef: D,
26
- open: g,
27
- disabled: !T || S,
28
- closeOnClickPopup: y,
29
- closeOnClickOutside: v && !_,
30
- placement: h,
31
- offsetX: x,
32
- offsetY: b,
33
- myWindow: k,
34
- onChange: j
35
- }), F = a({
36
- popupRef: D,
37
- open: g,
38
- positioned: !!P,
39
- enabled: !!T && !S
40
- }), I = o((e) => {
41
- F(e), M(e);
42
- }, [F, M]), L = s(() => ({
43
- popupRef: D,
44
- openPopup: g,
45
- parameters: P,
46
- onClick: N
47
- }), [
48
- N,
49
- g,
50
- P
25
+ }, [D]), [, , R, z, , B] = i({
26
+ ref: M,
27
+ popupRef: N,
28
+ open: b,
29
+ disabled: !k || E,
30
+ closeOnClickPopup: C,
31
+ closeOnClickOutside: S && !x,
32
+ placement: y,
33
+ offsetX: T,
34
+ offsetY: w,
35
+ myWindow: F,
36
+ onChange: L
37
+ }), [V, H] = u(null);
38
+ s(() => {
39
+ b && k && !V && H(g(M.current));
40
+ }, [
41
+ b,
42
+ k,
43
+ V,
44
+ M
51
45
  ]);
52
- return /* @__PURE__ */ d(n, {
53
- ref: e,
54
- className: f("plitzi-component__dropdown", m, { "container--empty--skip": !T && !p }),
55
- onClick: I,
56
- children: [/* @__PURE__ */ u(r, {
57
- value: L,
58
- children: p
59
- }), g && _ && T && /* @__PURE__ */ u("div", {
60
- ref: O,
61
- className: f("plitzi-component__dropdown__background-container", w.backgroundContainer),
62
- onClick: A
63
- })]
46
+ let U = k ? V : null, W = a({
47
+ rootRef: M,
48
+ popupRef: N,
49
+ open: b,
50
+ positioned: !!B,
51
+ enabled: !!k && !E
52
+ }), G = o((e) => {
53
+ W(e), R(e);
54
+ }, [W, R]), K = c(() => ({
55
+ popupRef: N,
56
+ openPopup: b,
57
+ parameters: B,
58
+ onClick: z,
59
+ layer: U
60
+ }), [
61
+ z,
62
+ b,
63
+ B,
64
+ U
65
+ ]), q = b && x && k && /* @__PURE__ */ f("div", {
66
+ ref: P,
67
+ className: m("plitzi-component__dropdown__background-container", O.backgroundContainer),
68
+ onClick: I
69
+ });
70
+ return /* @__PURE__ */ p(n, {
71
+ ref: M,
72
+ className: m("plitzi-component__dropdown", v, { "container--empty--skip": !k && !_ }),
73
+ onClick: G,
74
+ children: [/* @__PURE__ */ f(r, {
75
+ value: K,
76
+ children: _
77
+ }), q && U ? h(q, U) : q]
64
78
  });
65
- }, m = e(p);
79
+ }, v = e(_);
66
80
  //#endregion
67
- export { p as Dropdown, m as default };
81
+ export { _ as Dropdown, v as default };
@@ -5,6 +5,8 @@ export type DropdownContextValue = {
5
5
  openPopup: boolean;
6
6
  parameters?: FloatingPosition;
7
7
  onClick: (e: MouseEvent) => void;
8
+ /** Where the open popup is drawn instead of in place: the space's root, once the menu has opened (see `Dropdown`). */
9
+ layer: HTMLElement | null;
8
10
  };
9
11
  declare const DropdownContext: import('react').Context<DropdownContextValue>;
10
12
  export default DropdownContext;