@selfhelp/shared 1.0.1 → 1.0.4

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,452 @@
1
+ // src/plugin-sdk/version.ts
2
+ var PLUGIN_API_VERSION = "1.0";
3
+ var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
4
+ function parseSemver(version) {
5
+ const match = SEMVER_REGEX.exec(version);
6
+ if (!match) {
7
+ throw new Error(`[plugin-sdk] not a valid semver: '${version}'.`);
8
+ }
9
+ return {
10
+ major: Number(match[1]),
11
+ minor: Number(match[2]),
12
+ patch: Number(match[3]),
13
+ prerelease: match[4]
14
+ };
15
+ }
16
+ function compareSemver(a, b) {
17
+ const pa = parseSemver(a);
18
+ const pb = parseSemver(b);
19
+ if (pa.major !== pb.major) return pa.major - pb.major;
20
+ if (pa.minor !== pb.minor) return pa.minor - pb.minor;
21
+ if (pa.patch !== pb.patch) return pa.patch - pb.patch;
22
+ if (pa.prerelease && pb.prerelease) return pa.prerelease.localeCompare(pb.prerelease);
23
+ if (pa.prerelease) return -1;
24
+ if (pb.prerelease) return 1;
25
+ return 0;
26
+ }
27
+ function satisfiesSemverRange(version, range) {
28
+ const v = parseSemver(version);
29
+ return range.split("||").some((clause) => clause.trim().split(/\s+/).every((part) => matchSingle(v, part.trim())));
30
+ }
31
+ function matchSingle(v, part) {
32
+ if (!part) return true;
33
+ if (part === "*" || part === "x") return true;
34
+ if (part.startsWith("^")) {
35
+ const target = parseSemver(part.slice(1));
36
+ if (target.major === 0) {
37
+ if (target.minor === 0) return v.major === 0 && v.minor === 0 && v.patch === target.patch;
38
+ return v.major === 0 && v.minor === target.minor && (v.patch > target.patch || v.patch === target.patch && !v.prerelease);
39
+ }
40
+ return v.major === target.major && compareSemverObj(v, target) >= 0;
41
+ }
42
+ if (part.startsWith("~")) {
43
+ const target = parseSemver(part.slice(1));
44
+ return v.major === target.major && v.minor === target.minor && v.patch >= target.patch;
45
+ }
46
+ if (part.startsWith(">=")) return compareSemverObj(v, parseSemver(part.slice(2).trim())) >= 0;
47
+ if (part.startsWith("<=")) return compareSemverObj(v, parseSemver(part.slice(2).trim())) <= 0;
48
+ if (part.startsWith(">")) return compareSemverObj(v, parseSemver(part.slice(1).trim())) > 0;
49
+ if (part.startsWith("<")) return compareSemverObj(v, parseSemver(part.slice(1).trim())) < 0;
50
+ if (part.startsWith("=")) return compareSemverObj(v, parseSemver(part.slice(1).trim())) === 0;
51
+ return compareSemverObj(v, parseSemver(part)) === 0;
52
+ }
53
+ function compareSemverObj(a, b) {
54
+ if (a.major !== b.major) return a.major - b.major;
55
+ if (a.minor !== b.minor) return a.minor - b.minor;
56
+ if (a.patch !== b.patch) return a.patch - b.patch;
57
+ if (a.prerelease && b.prerelease) return a.prerelease.localeCompare(b.prerelease);
58
+ if (a.prerelease) return -1;
59
+ if (b.prerelease) return 1;
60
+ return 0;
61
+ }
62
+ function isPluginApiCompatible(required, host = PLUGIN_API_VERSION) {
63
+ const [reqMajor, reqMinor] = required.split(".").map((p) => Number(p));
64
+ const [hostMajor, hostMinor] = host.split(".").map((p) => Number(p));
65
+ if (Number.isNaN(reqMajor) || Number.isNaN(reqMinor) || Number.isNaN(hostMajor) || Number.isNaN(hostMinor)) {
66
+ return false;
67
+ }
68
+ if (hostMajor !== reqMajor) return false;
69
+ return hostMinor >= reqMinor;
70
+ }
71
+ function assertPluginApiVersion(required) {
72
+ const [reqMajor, reqMinor] = required.split(".").map((p) => Number(p));
73
+ const [hostMajor, hostMinor] = PLUGIN_API_VERSION.split(".").map((p) => Number(p));
74
+ if (Number.isNaN(reqMajor) || Number.isNaN(reqMinor)) {
75
+ throw new Error(`[plugin-sdk] invalid pluginApiVersion '${required}'.`);
76
+ }
77
+ if (hostMajor !== reqMajor) {
78
+ throw new Error(
79
+ `[plugin-sdk] incompatible pluginApiVersion: plugin wants '${required}' but host is '${PLUGIN_API_VERSION}'.`
80
+ );
81
+ }
82
+ if (hostMinor < reqMinor) {
83
+ throw new Error(
84
+ `[plugin-sdk] host SDK too old for plugin: plugin wants '${required}', host is '${PLUGIN_API_VERSION}'.`
85
+ );
86
+ }
87
+ }
88
+ function assertCmsCompatibility(cmsVersion, range) {
89
+ if (!satisfiesSemverRange(cmsVersion, range)) {
90
+ throw new Error(
91
+ `[plugin-sdk] CMS version '${cmsVersion}' does not satisfy plugin compatibility range '${range}'.`
92
+ );
93
+ }
94
+ }
95
+ function assertPluginVersionSemantics(prevVersion, nextVersion, options) {
96
+ const next = parseSemver(nextVersion);
97
+ if (!prevVersion) {
98
+ return;
99
+ }
100
+ const prev = parseSemver(prevVersion);
101
+ const bumpedMajor = next.major > prev.major;
102
+ const bumpedMinor = next.minor > prev.minor && next.major === prev.major;
103
+ const bumpedPatch = next.patch > prev.patch && next.minor === prev.minor && next.major === prev.major;
104
+ if (bumpedMajor) {
105
+ return;
106
+ }
107
+ if (bumpedMinor) {
108
+ if (!options.hasMigration) {
109
+ throw new Error(
110
+ `[plugin-sdk] plugin minor bump (${prevVersion} -> ${nextVersion}) must ship a DB migration.`
111
+ );
112
+ }
113
+ return;
114
+ }
115
+ if (bumpedPatch) {
116
+ if (options.hasMigration) {
117
+ throw new Error(
118
+ `[plugin-sdk] plugin patch bump (${prevVersion} -> ${nextVersion}) must not ship a DB migration.`
119
+ );
120
+ }
121
+ return;
122
+ }
123
+ if (compareSemver(nextVersion, prevVersion) <= 0) {
124
+ throw new Error(
125
+ `[plugin-sdk] plugin version did not increase: prev '${prevVersion}', next '${nextVersion}'.`
126
+ );
127
+ }
128
+ }
129
+
130
+ // src/registry/styles.registry.ts
131
+ var BASE_STYLE_REGISTRY = {
132
+ // ===== auth =====
133
+ login: { description: "User login form", category: "auth", frontendOnly: true, canHaveChildren: false },
134
+ register: { description: "User registration form", category: "auth", frontendOnly: true, canHaveChildren: false },
135
+ validate: { description: "Email/account validation flow", category: "auth", frontendOnly: true, canHaveChildren: true },
136
+ resetPassword: { description: "Reset password form", category: "auth", frontendOnly: true, canHaveChildren: false },
137
+ twoFactorAuth: { description: "Two-factor auth code form", category: "auth", frontendOnly: true, canHaveChildren: false },
138
+ profile: { description: "User profile management", category: "auth", frontendOnly: true, canHaveChildren: false },
139
+ // ===== layout =====
140
+ container: { description: "Mantine Container with responsive max-width", category: "layout", frontendOnly: true, canHaveChildren: true },
141
+ box: { description: "Generic Mantine Box wrapper", category: "layout", frontendOnly: true, canHaveChildren: true },
142
+ flex: { description: "Mantine Flex layout", category: "layout", frontendOnly: true, canHaveChildren: true },
143
+ group: { description: "Mantine Group horizontal layout", category: "layout", frontendOnly: true, canHaveChildren: true },
144
+ stack: { description: "Mantine Stack vertical layout", category: "layout", frontendOnly: true, canHaveChildren: true },
145
+ "simple-grid": { description: "Mantine SimpleGrid", category: "layout", frontendOnly: true, canHaveChildren: true },
146
+ grid: { description: "Mantine Grid", category: "layout", frontendOnly: true, canHaveChildren: true },
147
+ "grid-column": { description: "Mantine Grid.Col", category: "layout", frontendOnly: true, canHaveChildren: true },
148
+ space: { description: "Mantine Space spacer", category: "layout", frontendOnly: true, canHaveChildren: false },
149
+ divider: { description: "Mantine Divider", category: "layout", frontendOnly: true, canHaveChildren: false },
150
+ paper: { description: "Mantine Paper surface", category: "layout", frontendOnly: true, canHaveChildren: true },
151
+ center: { description: "Mantine Center alignment", category: "layout", frontendOnly: true, canHaveChildren: true },
152
+ "scroll-area": { description: "Mantine ScrollArea", category: "layout", frontendOnly: true, canHaveChildren: true },
153
+ card: { description: "Mantine Card", category: "layout", frontendOnly: true, canHaveChildren: true },
154
+ "card-segment": { description: "Mantine Card.Section", category: "layout", frontendOnly: true, canHaveChildren: true },
155
+ "aspect-ratio": { description: "Mantine AspectRatio wrapper", category: "layout", frontendOnly: true, canHaveChildren: true },
156
+ "background-image": { description: "Mantine BackgroundImage", category: "layout", frontendOnly: true, canHaveChildren: true },
157
+ // ===== typography =====
158
+ title: { description: "Mantine Title", category: "typography", frontendOnly: true, canHaveChildren: false },
159
+ text: { description: "Mantine Text", category: "typography", frontendOnly: true, canHaveChildren: false },
160
+ code: { description: "Mantine Code (inline / block)", category: "typography", frontendOnly: true, canHaveChildren: false },
161
+ highlight: { description: "Mantine Highlight", category: "typography", frontendOnly: true, canHaveChildren: false },
162
+ blockquote: { description: "Mantine Blockquote", category: "typography", frontendOnly: true, canHaveChildren: false },
163
+ "html-tag": { description: "Generic HTML tag wrapper (web), maps to View on RN", category: "typography", frontendOnly: true, canHaveChildren: true },
164
+ kbd: { description: "Mantine Kbd", category: "typography", frontendOnly: true, canHaveChildren: false },
165
+ typography: { description: "Mantine Typography wrapper", category: "typography", frontendOnly: true, canHaveChildren: true },
166
+ fieldset: { description: "Mantine Fieldset", category: "typography", frontendOnly: true, canHaveChildren: true },
167
+ spoiler: { description: "Mantine Spoiler reveal", category: "typography", frontendOnly: true, canHaveChildren: true },
168
+ // ===== media =====
169
+ image: { description: "Mantine Image / RN Image", category: "media", frontendOnly: true, canHaveChildren: false },
170
+ video: { description: "HTML5 video / expo-video", category: "media", frontendOnly: true, canHaveChildren: false },
171
+ audio: { description: "HTML5 audio / expo-audio", category: "media", frontendOnly: true, canHaveChildren: false },
172
+ figure: { description: "Figure with caption", category: "media", frontendOnly: true, canHaveChildren: true },
173
+ carousel: { description: "Embla on web, reanimated-carousel on RN", category: "media", frontendOnly: true, canHaveChildren: true },
174
+ // ===== interactive =====
175
+ button: { description: "Mantine Button / HeroUI Button", category: "interactive", frontendOnly: true, canHaveChildren: false },
176
+ link: { description: "Anchor / Pressable navigation", category: "interactive", frontendOnly: true, canHaveChildren: false },
177
+ "action-icon": { description: "Mantine ActionIcon", category: "interactive", frontendOnly: true, canHaveChildren: false },
178
+ alert: { description: "Mantine Alert", category: "interactive", frontendOnly: true, canHaveChildren: true },
179
+ badge: { description: "Mantine Badge", category: "interactive", frontendOnly: true, canHaveChildren: false },
180
+ avatar: { description: "Mantine Avatar", category: "interactive", frontendOnly: true, canHaveChildren: false },
181
+ chip: { description: "Mantine Chip", category: "interactive", frontendOnly: true, canHaveChildren: false },
182
+ indicator: { description: "Mantine Indicator dot", category: "interactive", frontendOnly: true, canHaveChildren: true },
183
+ "theme-icon": { description: "Mantine ThemeIcon", category: "interactive", frontendOnly: true, canHaveChildren: false },
184
+ notification: { description: "Mantine Notification", category: "interactive", frontendOnly: true, canHaveChildren: false },
185
+ // ===== forms =====
186
+ "form-log": { description: "Append-only form (one row per submit)", category: "forms", frontendOnly: true, canHaveChildren: true },
187
+ "form-record": { description: "Per-user record form", category: "forms", frontendOnly: true, canHaveChildren: true },
188
+ input: { description: "Plain HTML input", category: "forms", frontendOnly: true, canHaveChildren: false },
189
+ "text-input": { description: "Mantine TextInput", category: "forms", frontendOnly: true, canHaveChildren: false },
190
+ textarea: { description: "Mantine Textarea", category: "forms", frontendOnly: true, canHaveChildren: false },
191
+ "rich-text-editor": { description: "Tiptap editor on web; READ-ONLY viewer on mobile v1", category: "forms", frontendOnly: true, canHaveChildren: false },
192
+ select: { description: "HTML select / Mantine Select", category: "forms", frontendOnly: true, canHaveChildren: false },
193
+ radio: { description: "Mantine Radio / RadioGroup", category: "forms", frontendOnly: true, canHaveChildren: false },
194
+ checkbox: { description: "Mantine Checkbox", category: "forms", frontendOnly: true, canHaveChildren: false },
195
+ slider: { description: "Mantine Slider", category: "forms", frontendOnly: true, canHaveChildren: false },
196
+ "range-slider": { description: "Mantine RangeSlider", category: "forms", frontendOnly: true, canHaveChildren: false },
197
+ datepicker: { description: "Mantine DatePicker", category: "forms", frontendOnly: true, canHaveChildren: false },
198
+ switch: { description: "Mantine Switch", category: "forms", frontendOnly: true, canHaveChildren: false },
199
+ combobox: { description: "Mantine Combobox", category: "forms", frontendOnly: true, canHaveChildren: false },
200
+ "color-input": { description: "Mantine ColorInput", category: "forms", frontendOnly: true, canHaveChildren: false },
201
+ "color-picker": { description: "Mantine ColorPicker", category: "forms", frontendOnly: true, canHaveChildren: false },
202
+ "file-input": { description: "Mantine FileInput / DocumentPicker on RN", category: "forms", frontendOnly: true, canHaveChildren: false },
203
+ "number-input": { description: "Mantine NumberInput", category: "forms", frontendOnly: true, canHaveChildren: false },
204
+ "segmented-control": { description: "Mantine SegmentedControl", category: "forms", frontendOnly: true, canHaveChildren: false },
205
+ rating: { description: "Mantine Rating", category: "forms", frontendOnly: true, canHaveChildren: false },
206
+ progress: { description: "Mantine Progress", category: "forms", frontendOnly: true, canHaveChildren: false },
207
+ "progress-root": { description: "Mantine Progress.Root", category: "forms", frontendOnly: true, canHaveChildren: true },
208
+ "progress-section": { description: "Mantine Progress.Section", category: "forms", frontendOnly: true, canHaveChildren: false },
209
+ // ===== composite =====
210
+ accordion: { description: "Mantine Accordion", category: "composite", frontendOnly: true, canHaveChildren: true },
211
+ "accordion-item": { description: "Mantine Accordion.Item", category: "composite", frontendOnly: true, canHaveChildren: true },
212
+ tabs: { description: "Mantine Tabs", category: "composite", frontendOnly: true, canHaveChildren: true },
213
+ tab: { description: "Mantine Tabs.Tab + Tabs.Panel pair", category: "composite", frontendOnly: true, canHaveChildren: true },
214
+ timeline: { description: "Mantine Timeline", category: "composite", frontendOnly: true, canHaveChildren: true },
215
+ list: { description: "Mantine List", category: "composite", frontendOnly: true, canHaveChildren: true },
216
+ "list-item": { description: "Mantine List.Item", category: "composite", frontendOnly: true, canHaveChildren: true },
217
+ entryList: { description: "Data-driven list of entries (form-log table)", category: "composite", frontendOnly: true, canHaveChildren: true },
218
+ entryRecord: { description: "Single-record container", category: "composite", frontendOnly: true, canHaveChildren: true },
219
+ entryRecordDelete: { description: "Inline delete confirmation for an entry", category: "composite", frontendOnly: true, canHaveChildren: false },
220
+ loop: { description: "Loop / repeater over backend-provided rows", category: "composite", frontendOnly: true, canHaveChildren: true }
221
+ };
222
+ var PLUGIN_STYLE_REGISTRY = {};
223
+ var REGISTERED_PLUGIN_KEYS = /* @__PURE__ */ new Map();
224
+ function extendStyleRegistry(entries, options) {
225
+ const { pluginId, pluginVersion } = options;
226
+ const ownedKeys = REGISTERED_PLUGIN_KEYS.get(pluginId) ?? /* @__PURE__ */ new Set();
227
+ const addedKeys = [];
228
+ for (const [name, entry] of Object.entries(entries)) {
229
+ if (Object.prototype.hasOwnProperty.call(BASE_STYLE_REGISTRY, name)) {
230
+ throw new Error(
231
+ `[shared/registry] plugin '${pluginId}' tried to register core style '${name}'.`
232
+ );
233
+ }
234
+ const existing = PLUGIN_STYLE_REGISTRY[name];
235
+ if (existing && existing.pluginId !== pluginId) {
236
+ throw new Error(
237
+ `[shared/registry] plugin '${pluginId}' tried to register style '${name}' already owned by '${existing.pluginId}'.`
238
+ );
239
+ }
240
+ PLUGIN_STYLE_REGISTRY[name] = {
241
+ ...entry,
242
+ pluginId,
243
+ pluginVersion
244
+ };
245
+ ownedKeys.add(name);
246
+ addedKeys.push(name);
247
+ }
248
+ REGISTERED_PLUGIN_KEYS.set(pluginId, ownedKeys);
249
+ return function dispose() {
250
+ for (const key of addedKeys) {
251
+ const existing = PLUGIN_STYLE_REGISTRY[key];
252
+ if (existing && existing.pluginId === pluginId) {
253
+ delete PLUGIN_STYLE_REGISTRY[key];
254
+ ownedKeys.delete(key);
255
+ }
256
+ }
257
+ if (ownedKeys.size === 0) {
258
+ REGISTERED_PLUGIN_KEYS.delete(pluginId);
259
+ }
260
+ };
261
+ }
262
+
263
+ // src/plugin-sdk/define.ts
264
+ function definePlugin(registration) {
265
+ assertPluginApiVersion(registration.pluginApiVersion);
266
+ if (registration.styles?.length) {
267
+ extendStyleRegistry(toRegistryRecord(registration.styles), {
268
+ pluginId: registration.id,
269
+ pluginVersion: registration.version
270
+ });
271
+ }
272
+ return registration;
273
+ }
274
+ function defineMobilePlugin(registration) {
275
+ assertPluginApiVersion(registration.pluginApiVersion);
276
+ if (registration.styles?.length) {
277
+ extendStyleRegistry(toRegistryRecord(registration.styles), {
278
+ pluginId: registration.id,
279
+ pluginVersion: registration.version
280
+ });
281
+ }
282
+ return registration;
283
+ }
284
+ function definePluginRealtimeTopic(descriptor) {
285
+ return descriptor;
286
+ }
287
+ function toRegistryRecord(styles) {
288
+ const out = {};
289
+ for (const style of styles) {
290
+ out[style.name] = {
291
+ description: style.description,
292
+ category: style.category,
293
+ frontendOnly: true,
294
+ canHaveChildren: style.canHaveChildren
295
+ };
296
+ }
297
+ return out;
298
+ }
299
+
300
+ // src/plugin-sdk/realtime.ts
301
+ import { useEffect, useRef, useState } from "react";
302
+ var DEFAULT_ENDPOINT = "/api/plugins/events";
303
+ var MAX_RECONNECT_DELAY_MS = 3e4;
304
+ var INITIAL_RECONNECT_DELAY_MS = 1e3;
305
+ function expandTopic(topic, params) {
306
+ return topic.replace(/\{([^}]+)\}/g, (_match, name) => {
307
+ const value = params[name];
308
+ if (value === void 0) {
309
+ throw new Error(
310
+ `usePluginRealtime: topic "${topic}" references {${name}} but topicParams.${name} was not provided.`
311
+ );
312
+ }
313
+ return encodeURIComponent(String(value));
314
+ });
315
+ }
316
+ function buildSseUrl(endpoint, pluginId, expandedTopic) {
317
+ const params = new URLSearchParams({
318
+ pluginId,
319
+ topic: expandedTopic
320
+ });
321
+ const separator = endpoint.includes("?") ? "&" : "?";
322
+ return `${endpoint}${separator}${params.toString()}`;
323
+ }
324
+ function isEventSourceAvailable() {
325
+ return typeof globalThis !== "undefined" && typeof globalThis.EventSource !== "undefined";
326
+ }
327
+ function defaultTransportFactory(url) {
328
+ const Ctor = globalThis.EventSource;
329
+ return new Ctor(url);
330
+ }
331
+ function usePluginRealtime(options) {
332
+ const {
333
+ pluginId,
334
+ topic,
335
+ topicParams = {},
336
+ enabled = true,
337
+ endpoint = DEFAULT_ENDPOINT,
338
+ transportFactory,
339
+ parse
340
+ } = options;
341
+ const [data, setData] = useState(null);
342
+ const [isOnline, setIsOnline] = useState(false);
343
+ const [lastEventAt, setLastEventAt] = useState(null);
344
+ const [error, setError] = useState(null);
345
+ const parseRef = useRef(parse);
346
+ parseRef.current = parse;
347
+ const topicParamsKey = JSON.stringify(topicParams);
348
+ useEffect(() => {
349
+ if (!enabled) {
350
+ setIsOnline(false);
351
+ return;
352
+ }
353
+ const factory = transportFactory ?? (isEventSourceAvailable() ? defaultTransportFactory : null);
354
+ if (factory === null) {
355
+ setIsOnline(false);
356
+ return;
357
+ }
358
+ let cancelled = false;
359
+ let transport = null;
360
+ let reconnectTimer = null;
361
+ let reconnectDelay = INITIAL_RECONNECT_DELAY_MS;
362
+ let expandedTopic;
363
+ try {
364
+ expandedTopic = expandTopic(topic, JSON.parse(topicParamsKey));
365
+ } catch (err) {
366
+ setError(err instanceof Error ? err : new Error(String(err)));
367
+ setIsOnline(false);
368
+ return;
369
+ }
370
+ const eventName = `plugin/${pluginId}/${expandedTopic}`;
371
+ const url = buildSseUrl(endpoint, pluginId, expandedTopic);
372
+ const onOpen = () => {
373
+ if (cancelled) return;
374
+ reconnectDelay = INITIAL_RECONNECT_DELAY_MS;
375
+ setIsOnline(true);
376
+ setError(null);
377
+ };
378
+ const onEvent = (evt) => {
379
+ if (cancelled) return;
380
+ const raw = evt.data;
381
+ if (typeof raw !== "string") return;
382
+ try {
383
+ const payload = parseRef.current ? parseRef.current(raw) : JSON.parse(raw);
384
+ setData(payload);
385
+ setLastEventAt(/* @__PURE__ */ new Date());
386
+ } catch (parseErr) {
387
+ setError(parseErr instanceof Error ? parseErr : new Error(String(parseErr)));
388
+ }
389
+ };
390
+ const onError = (evt) => {
391
+ if (cancelled || !transport) return;
392
+ setIsOnline(false);
393
+ setError(evt instanceof Error ? evt : new Error("Plugin realtime transport error"));
394
+ if (transport.readyState === 2) {
395
+ try {
396
+ transport.close();
397
+ } catch {
398
+ }
399
+ transport = null;
400
+ reconnectTimer = setTimeout(connect, reconnectDelay);
401
+ reconnectDelay = Math.min(reconnectDelay * 2, MAX_RECONNECT_DELAY_MS);
402
+ }
403
+ };
404
+ const connect = () => {
405
+ if (cancelled) return;
406
+ try {
407
+ transport = factory(url);
408
+ } catch (createErr) {
409
+ setError(createErr instanceof Error ? createErr : new Error(String(createErr)));
410
+ setIsOnline(false);
411
+ return;
412
+ }
413
+ transport.addEventListener("open", onOpen);
414
+ transport.addEventListener(eventName, onEvent);
415
+ transport.addEventListener("message", onEvent);
416
+ transport.addEventListener("error", onError);
417
+ };
418
+ connect();
419
+ return () => {
420
+ cancelled = true;
421
+ if (reconnectTimer !== null) {
422
+ clearTimeout(reconnectTimer);
423
+ }
424
+ if (transport) {
425
+ try {
426
+ transport.removeEventListener("open", onOpen);
427
+ transport.removeEventListener(eventName, onEvent);
428
+ transport.removeEventListener("message", onEvent);
429
+ transport.removeEventListener("error", onError);
430
+ transport.close();
431
+ } catch {
432
+ }
433
+ transport = null;
434
+ }
435
+ };
436
+ }, [enabled, endpoint, pluginId, topic, topicParamsKey, transportFactory]);
437
+ return { data, isOnline, lastEventAt, error };
438
+ }
439
+ export {
440
+ PLUGIN_API_VERSION,
441
+ assertCmsCompatibility,
442
+ assertPluginApiVersion,
443
+ assertPluginVersionSemantics,
444
+ compareSemver,
445
+ defineMobilePlugin,
446
+ definePlugin,
447
+ definePluginRealtimeTopic,
448
+ isPluginApiCompatible,
449
+ parseSemver,
450
+ satisfiesSemverRange,
451
+ usePluginRealtime
452
+ };
@@ -1,2 +1,57 @@
1
- export { aj as IStyleRegistryEntry, az as STYLE_REGISTRY, bg as TStyleImplMap, bh as TStyleRegistryKey, bi as _AssertRegistryMatchesStyleName, bj as getRegistryEntry, bk as isKnownStyleName } from '../index-Bg60YTsF.mjs';
1
+ import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry } from '../styles.registry-C3bux91U.mjs';
2
+ export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, b as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, c as _resetPluginStyleRegistry, e as extendStyleRegistry, g as getMergedStyleRegistry, d as getPluginStyleRegistry } from '../styles.registry-C3bux91U.mjs';
2
3
  import '../common-B96dASgu.mjs';
4
+
5
+ /**
6
+ * Open style-name type: a core `TStyleName` literal OR any plugin style
7
+ * name. The `string & {}` keeps autocomplete for core names while still
8
+ * accepting plugin keys at type level.
9
+ */
10
+ type TAnyStyleName = TStyleName | (string & {});
11
+ /**
12
+ * Helper for renderers: produces a typed map shape that requires every
13
+ * core registry key to be implemented. Pass this to your dispatcher and
14
+ * let TypeScript enforce 100% style coverage for core styles. Plugin
15
+ * styles are dispatched through a separate `IPluginStyleImplMap`.
16
+ *
17
+ * type IStyleImpls = TStyleImplMap<React.FC<{ style: TStyle }>>;
18
+ *
19
+ * `keyof TStyleImplMap<...>` is exactly the union of *core* style names.
20
+ */
21
+ type TStyleImplMap<TImpl> = {
22
+ readonly [K in TStyleName]: TImpl;
23
+ };
24
+ /**
25
+ * Runtime-extensible map: plugin-contributed style implementations
26
+ * keyed by plugin style name. Renderers merge this with their
27
+ * `TStyleImplMap<TImpl>` at boot.
28
+ */
29
+ type TPluginStyleImplMap<TImpl> = Record<string, TImpl>;
30
+ /**
31
+ * Get an entry from the **core** registry. Returns undefined if the
32
+ * `style_name` is not a known core style. Use `getRegistryEntryAny()`
33
+ * to also resolve plugin styles.
34
+ */
35
+ declare function getRegistryEntry(name: string): IStyleRegistryEntry | undefined;
36
+ /**
37
+ * Get an entry from either the core or the plugin registry. Returns
38
+ * undefined if the `style_name` is not registered (the renderer should
39
+ * fall back to `UnknownStyle`).
40
+ */
41
+ declare function getRegistryEntryAny(name: string): IStyleRegistryEntry | IPluginStyleRegistryEntry | undefined;
42
+ /**
43
+ * Type guard to narrow a string to `TStyleName` (core styles only).
44
+ */
45
+ declare function isKnownStyleName(name: string): name is TStyleName;
46
+ /**
47
+ * Type guard for any registered style — core or plugin.
48
+ */
49
+ declare function isRegisteredStyleName(name: string): boolean;
50
+ /**
51
+ * For a known plugin style, return the owning `pluginId`. Useful for
52
+ * mobile to construct the "Open on web" fallback link when the plugin
53
+ * style is not bundled in the current build.
54
+ */
55
+ declare function getStylePluginId(name: string): string | undefined;
56
+
57
+ export { IPluginStyleRegistryEntry, IStyleRegistryEntry, type TAnyStyleName, type TPluginStyleImplMap, type TStyleImplMap, getRegistryEntry, getRegistryEntryAny, getStylePluginId, isKnownStyleName, isRegisteredStyleName };
@@ -1,2 +1,57 @@
1
- export { aj as IStyleRegistryEntry, az as STYLE_REGISTRY, bg as TStyleImplMap, bh as TStyleRegistryKey, bi as _AssertRegistryMatchesStyleName, bj as getRegistryEntry, bk as isKnownStyleName } from '../index-DEOVT86P.js';
1
+ import { T as TStyleName, I as IStyleRegistryEntry, a as IPluginStyleRegistryEntry } from '../styles.registry-Cr961HQ0.js';
2
+ export { B as BASE_STYLE_REGISTRY, S as STYLE_REGISTRY, b as TStyleRegistryKey, _ as _AssertRegistryMatchesStyleName, c as _resetPluginStyleRegistry, e as extendStyleRegistry, g as getMergedStyleRegistry, d as getPluginStyleRegistry } from '../styles.registry-Cr961HQ0.js';
2
3
  import '../common-B96dASgu.js';
4
+
5
+ /**
6
+ * Open style-name type: a core `TStyleName` literal OR any plugin style
7
+ * name. The `string & {}` keeps autocomplete for core names while still
8
+ * accepting plugin keys at type level.
9
+ */
10
+ type TAnyStyleName = TStyleName | (string & {});
11
+ /**
12
+ * Helper for renderers: produces a typed map shape that requires every
13
+ * core registry key to be implemented. Pass this to your dispatcher and
14
+ * let TypeScript enforce 100% style coverage for core styles. Plugin
15
+ * styles are dispatched through a separate `IPluginStyleImplMap`.
16
+ *
17
+ * type IStyleImpls = TStyleImplMap<React.FC<{ style: TStyle }>>;
18
+ *
19
+ * `keyof TStyleImplMap<...>` is exactly the union of *core* style names.
20
+ */
21
+ type TStyleImplMap<TImpl> = {
22
+ readonly [K in TStyleName]: TImpl;
23
+ };
24
+ /**
25
+ * Runtime-extensible map: plugin-contributed style implementations
26
+ * keyed by plugin style name. Renderers merge this with their
27
+ * `TStyleImplMap<TImpl>` at boot.
28
+ */
29
+ type TPluginStyleImplMap<TImpl> = Record<string, TImpl>;
30
+ /**
31
+ * Get an entry from the **core** registry. Returns undefined if the
32
+ * `style_name` is not a known core style. Use `getRegistryEntryAny()`
33
+ * to also resolve plugin styles.
34
+ */
35
+ declare function getRegistryEntry(name: string): IStyleRegistryEntry | undefined;
36
+ /**
37
+ * Get an entry from either the core or the plugin registry. Returns
38
+ * undefined if the `style_name` is not registered (the renderer should
39
+ * fall back to `UnknownStyle`).
40
+ */
41
+ declare function getRegistryEntryAny(name: string): IStyleRegistryEntry | IPluginStyleRegistryEntry | undefined;
42
+ /**
43
+ * Type guard to narrow a string to `TStyleName` (core styles only).
44
+ */
45
+ declare function isKnownStyleName(name: string): name is TStyleName;
46
+ /**
47
+ * Type guard for any registered style — core or plugin.
48
+ */
49
+ declare function isRegisteredStyleName(name: string): boolean;
50
+ /**
51
+ * For a known plugin style, return the owning `pluginId`. Useful for
52
+ * mobile to construct the "Open on web" fallback link when the plugin
53
+ * style is not bundled in the current build.
54
+ */
55
+ declare function getStylePluginId(name: string): string | undefined;
56
+
57
+ export { IPluginStyleRegistryEntry, IStyleRegistryEntry, type TAnyStyleName, type TPluginStyleImplMap, type TStyleImplMap, getRegistryEntry, getRegistryEntryAny, getStylePluginId, isKnownStyleName, isRegisteredStyleName };