@plugmatica/blocks 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Plugmatica contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,155 @@
1
- # Temporary Holding Version
1
+ # @plugmatica/blocks
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Props-first UI compositions built from the existing Plugmatica UI-kit, with the
4
+ original resource, mutation and editor helpers retained. Blocks has no stylesheet,
5
+ new design tokens, router, cache, inferred endpoints or domain DTOs.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pnpm add @plugmatica/blocks@beta @plugmatica/ui-kit@beta @plugmatica/plugin-sdk@beta @plugmatica/i18n@beta react react-dom react-hook-form
11
+ ```
12
+
13
+ Host-loaded plugins must use the host's compatible shared dependency instances.
14
+
15
+ ## Visual blocks
16
+
17
+ | Export | Composition |
18
+ | --- | --- |
19
+ | CollectionPage | Page + PageHeader + CollectionBlock |
20
+ | CollectionBlock | DataTable + empty/error feedback |
21
+ | FormBlock | Form + typed fields + error summary + actions |
22
+ | EditorSheet | Sheet + FormBlock + guarded dirty dismissal |
23
+ | ConnectionPickerSheet | Sheet + provider-neutral host-managed Connection selection |
24
+ | SettingsBlock | Card + FormBlock |
25
+ | DetailsBlock | Card + DescriptionList |
26
+ | ConfirmDialog | Dialog + guarded async confirmation |
27
+
28
+ ```tsx
29
+ import { CollectionPage, usePluginResource, useResourceTable } from "@plugmatica/blocks";
30
+
31
+ const resource = usePluginResource<RecordRow[]>("/records");
32
+ const table = useResourceTable(resource);
33
+ return (
34
+ <CollectionPage<RecordRow>
35
+ extension="records.list"
36
+ header={{ title: t("records.title") }}
37
+ table={{
38
+ ...table,
39
+ columns: [{ accessorKey: "name", header: t("records.name") }],
40
+ getRowId: (record) => record.id,
41
+ rowActions: [{ key: "edit", onSelect: openEditor }],
42
+ empty: { title: t("records.empty") },
43
+ }}
44
+ />
45
+ );
46
+ ```
47
+
48
+ This fragment assumes the plugin owns RecordRow, translations and openEditor.
49
+ Use stable local definitions: the compiler recognizes blocks and forwards nested
50
+ identities to standard UI-kit components. Put lifecycle spreads first. Keep
51
+ field/action identities static; use hidden/disabled flags instead of filtering
52
+ configuration. Existing renderRowActions and domain-content escape hatches remain.
53
+
54
+ ## Package boundaries
55
+
56
+ UI-kit owns visual primitives and semantic contracts; Data-viz owns charts.
57
+ Blocks owns reusable UI combinations and general lifecycle. Plugins own DTOs,
58
+ permissions, validation, API calls, revision checks and navigation. Plugins never
59
+ import another plugin; use locally declared runtime extension targets instead.
60
+ The package needs no additional provider or federation singleton. It uses the
61
+ host's existing React, UI-kit, plugin SDK and React Hook Form peers.
62
+
63
+ ## Documentation
64
+
65
+ The dedicated public docs section is `/blocks/intro`, with runnable previews, exact
66
+ demo source, integration recipes, API-at-a-glance tables, compiler/builder rules,
67
+ accessibility behavior and a registry-driven interactive gallery. The site is
68
+ maintained separately from this SDK repository; focused demo source remains
69
+ under `src/demo/*` in the Blocks package.
70
+ Public documentation and live examples: https://plugmatica.com/plugmatica/blocks/intro
71
+
72
+ For an isolated package consumer, install the compatible beta releases of
73
+ `@plugmatica/blocks`, `@plugmatica/ui-kit`, `@plugmatica/plugin-sdk`, and their
74
+ required peers. In a Plugmatica plugin, use the versions shared by the host;
75
+ plugins remain host-loaded Module Federation remotes, not standalone apps.
76
+
77
+ ## Resource and mutation contracts
78
+
79
+ `usePluginResource<T>(path, body?, options?)` uses the current plugin-scoped API.
80
+ Omitting the body or passing `undefined` means GET. Any JSON body, including
81
+ `null`, `false` or `0`, means POST. Pass `undefined` as the second argument when
82
+ supplying GET options in the third argument; there is no explicit method option.
83
+ POST is for **read/search endpoints only**, never side-effectful creation. Body
84
+ content, not object reference equality, determines request identity. Bodies must
85
+ be JSON-serializable. Scoped API changes always clear prior data, even when
86
+ `keepPreviousData` is enabled; callers cannot override this scope boundary.
87
+
88
+ `useAsyncResource<T>(load, options?)` supports typed-client adapters. Memoize
89
+ `load` with `useCallback`. It receives an AbortSignal; a generation guard also
90
+ ignores obsolete responses when a client cannot forward that signal. Read-only
91
+ execution begins in a microtask so StrictMode's abandoned probe can be cancelled
92
+ before transport. A changed loader clears data unless `keepPreviousData` is
93
+ explicitly enabled. A changed `scopeKey` or `enabled: false` always hides prior
94
+ data. An obsolete refresh callback is refused after ownership changes.
95
+
96
+ Both return `value`, `error`, `loading`, `refresh`, `reload` and `setValue`.
97
+ `refresh()` is safe for events: failure populates `error` and returns undefined.
98
+ `reload()` returns the loaded value and rejects on failure, cancellation or a
99
+ disabled resource. Catch that rejection at imperative call sites. Background
100
+ refresh retains rows; error presentation follows the owning UI component.
101
+ These hooks do not deduplicate different hook instances or cache across screens.
102
+
103
+ `useAsyncAction(fn)` supplies `pending`, `error`, `run`, `isPending`, and `reset`.
104
+ `run` resolves to `{ status: "success", value }`, `{ status: "error", error }`,
105
+ or `{ status: "busy" }`. It captures synchronous exceptions and rejections.
106
+ Writes are not aborted on unmount: cancellation cannot undo a server mutation.
107
+ Only React state updates are suppressed after unmount.
108
+
109
+ `ResourceError`, `ResourceLoading` and `ResourceBoundary` use existing UI-kit
110
+ components. Generic errors do not expose raw server details; HTTP 403/404 receive
111
+ shared permission/not-found text. Plugin-specific wording can be passed to
112
+ `ResourceError`. `ResourceBoundary` accepts a render function for non-table
113
+ content; `useResourceTable` binds lifecycle props to DataTable or CollectionBlock.
114
+ Host navigation and path observation belong to `@plugmatica/plugin-sdk`, not Blocks.
115
+ Use `usePluginCurrentPath()` for reactive paths, `usePluginRouteMatch()` for route
116
+ parameters and `usePluginNavigation()` for navigation. Embedded hosts without a
117
+ subscription still work. The former `usePluginPath()` export was removed during
118
+ pre-public development; it is not part of the first public `0.1.0` beta. Migrate
119
+ pre-public consumers to `usePluginCurrentPath()` from the SDK. There is no
120
+ compatibility alias.
121
+
122
+
123
+ ## Verification
124
+
125
+ From the SDK repository root, run the package typecheck, test suite and build
126
+ after a frozen dependency install:
127
+
128
+ ```bash
129
+ pnpm --filter @plugmatica/blocks run typecheck
130
+ pnpm --filter @plugmatica/blocks run test
131
+ pnpm --filter @plugmatica/blocks run build
132
+ ```
133
+
134
+ These source/package checks do not replace host-integrated plugin acceptance or
135
+ public API release approval. The documentation build belongs to the separate
136
+ documentation repository.
137
+
138
+ ## Dependent Connection configuration presets
139
+
140
+ Connection types may optionally annotate an `enum` property inside `configSchema.properties` with `x-plugmatica-presets`: an object mapping enum values to sibling configuration values. The shared `ConnectionEditorForm` applies all declared sibling values when the selector changes; both Settings Connections and the contextual `ConnectionPickerSheet` use the same implementation. The selected preset is also applied on creation to keep defaults consistent. Example:
141
+
142
+ ```json
143
+ {
144
+ "properties": {
145
+ "region": { "type": "string", "enum": ["us", "eu"], "default": "us", "x-plugmatica-presets": { "eu": { "apiOrigin": "https://api.example.eu" }, "us": { "apiOrigin": "https://api.example.com" } } },
146
+ "apiOrigin": { "type": "string", "x-plugmatica-ui": "readonly" }
147
+ }
148
+ }
149
+ ```
150
+
151
+ Presets change only explicitly declared non-constant, non-hidden sibling *config* fields, never write-only credential fields. Use `x-plugmatica-ui: "readonly"` on fully derived fields. The provider and host must **still validate** the resulting Connection before any network egress; presets are only an authoring aid and introduce no plugin-to-plugin dependencies.
152
+
153
+ ## License
154
+
155
+ MIT.