@selfhelp/shared 1.29.0 → 1.31.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/CHANGELOG.md +83 -0
- package/dist/index.d.mts +35 -85
- package/dist/index.d.ts +35 -85
- package/dist/index.js +18 -5
- package/dist/index.mjs +15 -5
- package/dist/inlineFormat-Duu5VLMU.d.mts +73 -0
- package/dist/inlineFormat-Duu5VLMU.d.ts +73 -0
- package/dist/{manifest-BNnCN1Qo.d.mts → manifest-DWHD0PQA.d.mts} +168 -1
- package/dist/{manifest-BNnCN1Qo.d.ts → manifest-DWHD0PQA.d.ts} +168 -1
- package/dist/plugin-sdk/index.d.mts +260 -7
- package/dist/plugin-sdk/index.d.ts +260 -7
- package/dist/plugin-sdk/index.js +174 -2
- package/dist/plugin-sdk/index.mjs +171 -2
- package/dist/plugin-sdk/sync-map.d.mts +22 -0
- package/dist/plugin-sdk/sync-map.d.ts +22 -0
- package/dist/plugin-sdk/sync-map.js +58 -0
- package/dist/plugin-sdk/sync-map.mjs +33 -0
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.d.ts +2 -2
- package/dist/{styles.registry-DnIJqEzM.d.mts → styles.registry-B2cyNdo3.d.mts} +26 -1
- package/dist/{styles.registry-C2ACy7H0.d.ts → styles.registry-G_KUYGPv.d.ts} +26 -1
- package/dist/testing/index.d.mts +1 -1
- package/dist/testing/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/content/__tests__/languageIndependent.test.ts +26 -0
- package/src/content/__tests__/languageIndependentLiteral.test.ts +62 -0
- package/src/content/formRecordPrefill.ts +9 -7
- package/src/content/index.ts +1 -0
- package/src/content/languageIndependent.ts +28 -0
- package/src/plugin-sdk/__tests__/define-sync.test.ts +106 -0
- package/src/plugin-sdk/__tests__/exports.test.ts +29 -0
- package/src/plugin-sdk/__tests__/host-services.test.ts +96 -6
- package/src/plugin-sdk/__tests__/sync-map.test.ts +48 -0
- package/src/plugin-sdk/__tests__/version.test.ts +9 -0
- package/src/plugin-sdk/host-services.ts +106 -0
- package/src/plugin-sdk/index.ts +31 -0
- package/src/plugin-sdk/manifest.ts +193 -0
- package/src/plugin-sdk/sync-map.ts +61 -0
- package/src/plugin-sdk/types.ts +142 -2
- package/src/plugin-sdk/version.ts +19 -2
- package/src/sync/__tests__/sync.test.ts +19 -0
- package/src/sync/sync.ts +3 -2
- package/src/sync/types.ts +9 -6
- package/src/types/api/form-lists.ts +16 -1
- package/src/types/api/forms.ts +10 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as
|
|
2
|
-
import { I as IStyleRegistryEntry } from '../styles.registry-
|
|
1
|
+
export { I as IPluginManifest, a as IPluginManifestAdminPage, b as IPluginManifestApiRoute, c as IPluginManifestAsset, d as IPluginManifestCacheCategory, e as IPluginManifestCapability, f as IPluginManifestCompatibility, g as IPluginManifestConflict, h as IPluginManifestDataAccess, i as IPluginManifestDependency, j as IPluginManifestExternalHost, k as IPluginManifestFeatureFlag, l as IPluginManifestField, m as IPluginManifestFieldType, n as IPluginManifestHealth, o as IPluginManifestJobConfigProperty, p as IPluginManifestJobConfigSchema, q as IPluginManifestJsonLogicOperation, r as IPluginManifestLookupExtension, s as IPluginManifestMobile, t as IPluginManifestPermission, u as IPluginManifestRateLimit, v as IPluginManifestRealtimeTopic, w as IPluginManifestRecurringJob, x as IPluginManifestScheduledJob, y as IPluginManifestSecurity, z as IPluginManifestSetting, A as IPluginManifestStyle, B as IPluginManifestStyleField, C as IPluginManifestStyleGroup, D as IPluginManifestTrustLevel, T as TPluginDomainEventName } from '../manifest-DWHD0PQA.js';
|
|
2
|
+
import { I as IStyleRegistryEntry } from '../styles.registry-G_KUYGPv.js';
|
|
3
|
+
import { IPluginSyncEntry } from './sync-map.js';
|
|
4
|
+
export { matchPluginSyncEntries } from './sync-map.js';
|
|
5
|
+
export { I as IInlineNode, p as parseInlineRich, s as stripHtmlToText } from '../inlineFormat-Duu5VLMU.js';
|
|
3
6
|
import '../common-qaDIAYS3.js';
|
|
4
7
|
|
|
5
8
|
/**
|
|
@@ -13,8 +16,16 @@ import '../common-qaDIAYS3.js';
|
|
|
13
16
|
* - major (1.x -> 2.0) — breaking SDK change.
|
|
14
17
|
*
|
|
15
18
|
* Independent from the npm `version` of `@selfhelp/shared`.
|
|
19
|
+
*
|
|
20
|
+
* `0.2.0` adds resource tags, the plugin sync map, manifest keys for settings /
|
|
21
|
+
* rate limits / JSON Logic / cache categories / action-plannable jobs, and the
|
|
22
|
+
* web SDK `resources` / `settings` / `sectionAnchor` surface (task
|
|
23
|
+
* `2026-11-25-plugin-resource-hooks`). It also covers the optional mobile host
|
|
24
|
+
* services `upload`, `requestPermission` / `openAppSettings` and
|
|
25
|
+
* `getPluginStorage`, and the `parseInlineRich` / `stripHtmlToText` /
|
|
26
|
+
* `IInlineNode` exports (the mobile renderer axis is `0.4.0`).
|
|
16
27
|
*/
|
|
17
|
-
declare const PLUGIN_API_VERSION: "0.
|
|
28
|
+
declare const PLUGIN_API_VERSION: "0.2.0";
|
|
18
29
|
/**
|
|
19
30
|
* Mobile renderer contract version. This is the SECOND, mobile-only
|
|
20
31
|
* compatibility axis (independent of `PLUGIN_API_VERSION`): it versions the
|
|
@@ -41,8 +52,17 @@ declare const PLUGIN_API_VERSION: "0.1.0";
|
|
|
41
52
|
* through the host router (correct in the native app AND the CMS web preview
|
|
42
53
|
* iframe) instead of touching `window.location` — an additive renderer feature.
|
|
43
54
|
* It is optional, so older plugins/hosts stay compatible.
|
|
55
|
+
*
|
|
56
|
+
* `0.4.0` adds three optional host services and one text-helper export (task
|
|
57
|
+
* `2026-11-25-plugin-resource-hooks`, C27 to C30): `upload` (multipart through
|
|
58
|
+
* the host with the host's token), `requestPermission` / `openAppSettings`
|
|
59
|
+
* (microphone and camera, asked by the app), `getPluginStorage` (a small device
|
|
60
|
+
* key-value store per server, user and plugin), and `parseInlineRich` /
|
|
61
|
+
* `stripHtmlToText` / `IInlineNode` exported from `plugin-sdk`. All members are
|
|
62
|
+
* optional, so a plugin feature-detects them; plugins declare `>=` ranges in
|
|
63
|
+
* `compatibility.mobile`.
|
|
44
64
|
*/
|
|
45
|
-
declare const MOBILE_RENDERER_VERSION: "0.
|
|
65
|
+
declare const MOBILE_RENDERER_VERSION: "0.4.0";
|
|
46
66
|
interface ISemver {
|
|
47
67
|
major: number;
|
|
48
68
|
minor: number;
|
|
@@ -389,6 +409,42 @@ interface IPluginLock {
|
|
|
389
409
|
* component type at registration time.
|
|
390
410
|
*/
|
|
391
411
|
type TPluginComponent<TProps = unknown> = (props: TProps) => unknown;
|
|
412
|
+
/**
|
|
413
|
+
* Where a plugin item is used (C7). Pages the caller may not read are counted
|
|
414
|
+
* only in `hidden_count`.
|
|
415
|
+
*/
|
|
416
|
+
interface IResourceUsage {
|
|
417
|
+
pages: Array<{
|
|
418
|
+
id: number;
|
|
419
|
+
keyword: string;
|
|
420
|
+
title: string | null;
|
|
421
|
+
draft_uses: boolean;
|
|
422
|
+
published_uses: boolean;
|
|
423
|
+
}>;
|
|
424
|
+
actions: Array<{
|
|
425
|
+
id: number;
|
|
426
|
+
name: string;
|
|
427
|
+
}>;
|
|
428
|
+
hidden_count: number;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* One item of `GET /admin/plugins/{pluginId}/settings` (C14). Secrets never
|
|
432
|
+
* carry a clear `value`; `hint` is the last 4 characters when the secret is
|
|
433
|
+
* long enough, otherwise null.
|
|
434
|
+
*/
|
|
435
|
+
interface IPluginSettingViewItem {
|
|
436
|
+
key: string;
|
|
437
|
+
label: string;
|
|
438
|
+
type: 'string' | 'number' | 'boolean' | 'url';
|
|
439
|
+
secret: boolean;
|
|
440
|
+
required: boolean;
|
|
441
|
+
has_value: boolean;
|
|
442
|
+
value: string | number | boolean | null;
|
|
443
|
+
hint: string | null;
|
|
444
|
+
overridden_by_env: boolean;
|
|
445
|
+
}
|
|
446
|
+
/** The C14 GET settings list for one plugin. */
|
|
447
|
+
type IPluginSettingsView = IPluginSettingViewItem[];
|
|
392
448
|
/**
|
|
393
449
|
* Definition of a CMS style contributed by a plugin.
|
|
394
450
|
*/
|
|
@@ -404,6 +460,49 @@ interface IStyleDefinition extends Omit<IStyleRegistryEntry, 'category'> {
|
|
|
404
460
|
/** Style implementation component (React or React Native). */
|
|
405
461
|
component: TPluginComponent;
|
|
406
462
|
}
|
|
463
|
+
/**
|
|
464
|
+
* The popup a page is shown in, as the host sees it. Outside a popup
|
|
465
|
+
* `inModal` is false and `closeModal()` does nothing, so a plugin can call
|
|
466
|
+
* it unconditionally (for example after a save, like the core form's
|
|
467
|
+
* `close_modal_on_save`).
|
|
468
|
+
*/
|
|
469
|
+
interface IPluginPageModal {
|
|
470
|
+
inModal: boolean;
|
|
471
|
+
closeModal: () => void;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* The page a plugin section is drawn on. A plugin endpoint that serves or
|
|
475
|
+
* accepts data for the section names the page and the section in every call
|
|
476
|
+
* (with this language, preview state and route), so the server can check
|
|
477
|
+
* access and read the section's settings itself (rule 7.7), like the core
|
|
478
|
+
* form and form list do.
|
|
479
|
+
*/
|
|
480
|
+
interface IPluginStylePage {
|
|
481
|
+
/** Page id; null while the page content is not known yet. */
|
|
482
|
+
id: number | null;
|
|
483
|
+
languageId: number | null;
|
|
484
|
+
/** Whether the page is shown as the editor's draft (preview mode). */
|
|
485
|
+
preview: boolean;
|
|
486
|
+
/** The page's declared route parameters (`page.route_params`). */
|
|
487
|
+
routeParams: Record<string, string>;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Props the host passes to a plugin style component (the `component` of an
|
|
491
|
+
* {@link IStyleDefinition}). `style` is the section as the page payload
|
|
492
|
+
* carries it (fields keyed by name).
|
|
493
|
+
*/
|
|
494
|
+
interface IPluginStyleProps {
|
|
495
|
+
style: Record<string, unknown>;
|
|
496
|
+
styleProps: Record<string, string>;
|
|
497
|
+
cssClass: string;
|
|
498
|
+
parentActive?: number;
|
|
499
|
+
childIndex?: number;
|
|
500
|
+
parentColor?: string;
|
|
501
|
+
/** The popup the page is shown in; a no-op outside one. */
|
|
502
|
+
pageModal: IPluginPageModal;
|
|
503
|
+
/** The page the section is on, to name in plugin calls. */
|
|
504
|
+
page: IPluginStylePage;
|
|
505
|
+
}
|
|
407
506
|
/**
|
|
408
507
|
* Props passed by the host's section-field editor to a plugin-supplied
|
|
409
508
|
* field renderer. The host owns the surrounding label / help tooltip /
|
|
@@ -605,6 +704,40 @@ interface IPluginApi {
|
|
|
605
704
|
realtime?: IPluginRealtimePublisher;
|
|
606
705
|
/** Host rich-text editor adapter. */
|
|
607
706
|
richTextEditor: IRichTextEditorAdapter;
|
|
707
|
+
/**
|
|
708
|
+
* The host's HTML sanitizer, with the same rules core pages use (web:
|
|
709
|
+
* DOMPurify, plus the host's link rewrites). Call it before rendering any
|
|
710
|
+
* CMS or user HTML; never bundle a sanitizer of your own. `inline` keeps
|
|
711
|
+
* inline markup only, `block` also keeps headings, lists and paragraphs.
|
|
712
|
+
*/
|
|
713
|
+
sanitizeHtml(html: string, mode: 'inline' | 'block'): string;
|
|
714
|
+
/**
|
|
715
|
+
* CSS selector for a rendered section element (C23). Returns
|
|
716
|
+
* `.section-<id>`. Web only.
|
|
717
|
+
*/
|
|
718
|
+
sectionAnchor(sectionId: number): string;
|
|
719
|
+
/** Where-used for a plugin item the caller may view (C7, C11). */
|
|
720
|
+
resources: {
|
|
721
|
+
usage(type: string, id: number): Promise<IResourceUsage>;
|
|
722
|
+
};
|
|
723
|
+
/**
|
|
724
|
+
* Optional host UI parts. `ResourceUsageList` is offered when the host
|
|
725
|
+
* ships a shared where-used list for delete warnings.
|
|
726
|
+
*/
|
|
727
|
+
ui?: {
|
|
728
|
+
ResourceUsageList: TPluginComponent<{
|
|
729
|
+
type: string;
|
|
730
|
+
id: number;
|
|
731
|
+
warnBeforeDelete?: boolean;
|
|
732
|
+
}>;
|
|
733
|
+
};
|
|
734
|
+
/**
|
|
735
|
+
* This plugin's settings as the host stores them (C14). Secrets show
|
|
736
|
+
* `has_value` only; clear values are never returned for secrets.
|
|
737
|
+
*/
|
|
738
|
+
settings: {
|
|
739
|
+
get(): Promise<IPluginSettingsView>;
|
|
740
|
+
};
|
|
608
741
|
/**
|
|
609
742
|
* Logger that respects the host's debug config. Avoid `console.log`
|
|
610
743
|
* in plugin code; route everything through this.
|
|
@@ -618,9 +751,18 @@ interface IPluginApi {
|
|
|
618
751
|
}
|
|
619
752
|
/**
|
|
620
753
|
* Same shape on mobile, minus the rich-text editor adapter when the
|
|
621
|
-
* plugin only supports read-only mobile rendering.
|
|
754
|
+
* plugin only supports read-only mobile rendering. Web-only C11 / C23 members
|
|
755
|
+
* are omitted. React Native does not render HTML, so there is no
|
|
756
|
+
* `sanitizeHtml` on mobile. HTML rule for mobile plugins:
|
|
757
|
+
* - Native React Native text: `parseInlineRich` (inline formatting and
|
|
758
|
+
* links) and `stripHtmlToText` (plain text), both exported from
|
|
759
|
+
* `@selfhelp/shared/plugin-sdk`.
|
|
760
|
+
* - HTML inside the plugin's own WebView: the plugin bundles a sanitizer into
|
|
761
|
+
* the WebView runtime and keeps a strict CSP. The host offers no sanitizer
|
|
762
|
+
* on mobile.
|
|
763
|
+
* - Web part: `api.sanitizeHtml`; never bundle a sanitizer there.
|
|
622
764
|
*/
|
|
623
|
-
interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor'> {
|
|
765
|
+
interface IMobilePluginApi extends Omit<IPluginApi, 'richTextEditor' | 'sanitizeHtml' | 'sectionAnchor' | 'resources' | 'ui' | 'settings'> {
|
|
624
766
|
/** Mobile builds without rich-text support set this to `null`. */
|
|
625
767
|
richTextEditor: IRichTextEditorAdapter | null;
|
|
626
768
|
}
|
|
@@ -654,6 +796,11 @@ interface IPluginRegistration {
|
|
|
654
796
|
* `field_types`) without the host having to hardcode the renderer.
|
|
655
797
|
*/
|
|
656
798
|
fieldRenderers?: IFieldRendererDefinition[];
|
|
799
|
+
/**
|
|
800
|
+
* Declarative sync map (C10). The host invalidates each matching
|
|
801
|
+
* `queryKey` as a prefix when a change notice carries a listed tag.
|
|
802
|
+
*/
|
|
803
|
+
sync?: IPluginSyncEntry[];
|
|
657
804
|
}
|
|
658
805
|
/**
|
|
659
806
|
* Returned by `defineMobilePlugin()` for the mobile side of a plugin.
|
|
@@ -668,6 +815,11 @@ interface IMobilePluginRegistration {
|
|
|
668
815
|
realtimeTopics?: IPluginRealtimeTopic[];
|
|
669
816
|
/** Mobile feature flags (mirror of the manifest flags). */
|
|
670
817
|
featureFlags?: IPluginFeatureFlag[];
|
|
818
|
+
/**
|
|
819
|
+
* Declarative sync map (C10). Same shape as the web registration; the
|
|
820
|
+
* mobile host invalidates matching query keys from `applySyncTags`.
|
|
821
|
+
*/
|
|
822
|
+
sync?: IPluginSyncEntry[];
|
|
671
823
|
}
|
|
672
824
|
|
|
673
825
|
/**
|
|
@@ -773,6 +925,67 @@ interface IMobileHostResponse<TData = unknown> {
|
|
|
773
925
|
*/
|
|
774
926
|
sessionExpired?: boolean;
|
|
775
927
|
}
|
|
928
|
+
/**
|
|
929
|
+
* One file part of a multipart upload the plugin asks the host to send
|
|
930
|
+
* (renderer 0.4.0, C27). Give exactly one of {@link uri} or {@link base64}.
|
|
931
|
+
*/
|
|
932
|
+
interface IMobileHostUploadFile {
|
|
933
|
+
/** Multipart part name (the field name the plugin's route reads). */
|
|
934
|
+
field: string;
|
|
935
|
+
/** File name sent to the server. */
|
|
936
|
+
name: string;
|
|
937
|
+
/** MIME type, e.g. `audio/m4a`. */
|
|
938
|
+
type: string;
|
|
939
|
+
/**
|
|
940
|
+
* `file://` or `content://` (native), `blob:` or `data:` (web preview).
|
|
941
|
+
* Exclusive with {@link base64}.
|
|
942
|
+
*/
|
|
943
|
+
uri?: string;
|
|
944
|
+
/** Raw base64 without a `data:` prefix. Exclusive with {@link uri}. */
|
|
945
|
+
base64?: string;
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* A protected multipart upload (renderer 0.4.0, C27). Same path rules as
|
|
949
|
+
* {@link IMobileHostRequest}: relative to the host API base, absolute URLs are
|
|
950
|
+
* refused.
|
|
951
|
+
*/
|
|
952
|
+
interface IMobileHostUploadRequest {
|
|
953
|
+
/** Path relative to the host API base, like {@link IMobileHostRequest.path}. */
|
|
954
|
+
path: string;
|
|
955
|
+
/** HTTP method. Defaults to `POST`. */
|
|
956
|
+
method?: 'POST' | 'PUT';
|
|
957
|
+
/** Text parts of the multipart body. */
|
|
958
|
+
fields?: Record<string, string>;
|
|
959
|
+
/** File parts. At least one is required. */
|
|
960
|
+
files: IMobileHostUploadFile[];
|
|
961
|
+
/** Extra request headers. */
|
|
962
|
+
headers?: Record<string, string>;
|
|
963
|
+
/** Query parameters appended to the path. */
|
|
964
|
+
query?: Record<string, string | number | boolean>;
|
|
965
|
+
}
|
|
966
|
+
/** What a plugin may ask the host to request from the system (C28). */
|
|
967
|
+
type TMobileHostPermission = 'microphone' | 'camera';
|
|
968
|
+
/**
|
|
969
|
+
* Answer to {@link IMobileHostServices.requestPermission}: `granted`, `denied`
|
|
970
|
+
* (the user said no and the app may ask again) or `blocked` (the system will
|
|
971
|
+
* not show the prompt again; send the user to {@link IMobileHostServices.openAppSettings}).
|
|
972
|
+
*/
|
|
973
|
+
type TMobileHostPermissionState = 'granted' | 'denied' | 'blocked';
|
|
974
|
+
/**
|
|
975
|
+
* Small device key-value store for one plugin, one user and one server (C29).
|
|
976
|
+
* Meant for drafts and view state. It is not encrypted: never keep secrets or
|
|
977
|
+
* tokens in it. The server still decides everything on submit.
|
|
978
|
+
*/
|
|
979
|
+
interface IMobilePluginStorage {
|
|
980
|
+
/** The stored value, or `null` when the key is not set. */
|
|
981
|
+
getItem(key: string): Promise<string | null>;
|
|
982
|
+
/** Stores a value; rejects with `Error('plugin_storage_full')` over the size cap and changes nothing. */
|
|
983
|
+
setItem(key: string, value: string): Promise<void>;
|
|
984
|
+
/** Removes one key. */
|
|
985
|
+
removeItem(key: string): Promise<void>;
|
|
986
|
+
/** Removes everything of this plugin, this user and this server only. */
|
|
987
|
+
clear(): Promise<void>;
|
|
988
|
+
}
|
|
776
989
|
/**
|
|
777
990
|
* Authenticated host services exposed to a plugin's mobile package. The
|
|
778
991
|
* host owns the token + refresh; the plugin only describes the request.
|
|
@@ -810,6 +1023,46 @@ interface IMobileHostServices {
|
|
|
810
1023
|
* gracefully rather than assume it exists.
|
|
811
1024
|
*/
|
|
812
1025
|
navigate?(target: string, external?: boolean): void;
|
|
1026
|
+
/**
|
|
1027
|
+
* Send a `multipart/form-data` request through the host (renderer 0.4.0).
|
|
1028
|
+
* The host attaches the token and client headers, makes one 401 refresh
|
|
1029
|
+
* retry and answers in the {@link IMobileHostResponse} shape, like
|
|
1030
|
+
* {@link request}. An absolute path is refused. Nothing is sent, and the
|
|
1031
|
+
* answer is `{ ok: false, status: 0, reason }`, when `reason` is
|
|
1032
|
+
* `invalid_upload` (no file, or a file with both or neither of `uri` and
|
|
1033
|
+
* `base64`) or `file_too_large` (one total size limit per request). The
|
|
1034
|
+
* host removes any temporary file it wrote for a `base64` input.
|
|
1035
|
+
*
|
|
1036
|
+
* Optional: an older host omits it, so a plugin MUST feature-detect
|
|
1037
|
+
* (`if (host.upload)`) and degrade gracefully.
|
|
1038
|
+
*/
|
|
1039
|
+
upload?<TData = unknown>(req: IMobileHostUploadRequest): Promise<IMobileHostResponse<TData>>;
|
|
1040
|
+
/**
|
|
1041
|
+
* Ask the system for microphone or camera access (renderer 0.4.0). Only the
|
|
1042
|
+
* app asks; a plugin in a WebView cannot. Resolves to `granted`, `denied`
|
|
1043
|
+
* or `blocked` ({@link TMobileHostPermissionState}); on `blocked` the plugin
|
|
1044
|
+
* should explain why it needs the permission and offer
|
|
1045
|
+
* {@link openAppSettings}.
|
|
1046
|
+
*
|
|
1047
|
+
* Optional: feature-detect (`if (host.requestPermission)`).
|
|
1048
|
+
*/
|
|
1049
|
+
requestPermission?(kind: TMobileHostPermission): Promise<TMobileHostPermissionState>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Open the app's system settings page so the user can change a `blocked`
|
|
1052
|
+
* permission (renderer 0.4.0). Does nothing in the web preview.
|
|
1053
|
+
*
|
|
1054
|
+
* Optional: feature-detect (`if (host.openAppSettings)`).
|
|
1055
|
+
*/
|
|
1056
|
+
openAppSettings?(): void;
|
|
1057
|
+
/**
|
|
1058
|
+
* Device storage for the given plugin id, scoped to the current server and
|
|
1059
|
+
* user (guest = 0), emptied on logout, server switch and a rejected token
|
|
1060
|
+
* refresh (renderer 0.4.0, C29). Throws when `pluginId` does not match the
|
|
1061
|
+
* manifest id pattern. Not for secrets.
|
|
1062
|
+
*
|
|
1063
|
+
* Optional: feature-detect (`if (host.getPluginStorage)`).
|
|
1064
|
+
*/
|
|
1065
|
+
getPluginStorage?(pluginId: string): IMobilePluginStorage;
|
|
813
1066
|
}
|
|
814
1067
|
/**
|
|
815
1068
|
* Register the host services implementation. Called once by the native
|
|
@@ -1006,4 +1259,4 @@ declare function isPluginRuntimeShimSpecifier(value: unknown): value is TPluginR
|
|
|
1006
1259
|
*/
|
|
1007
1260
|
declare const PLUGIN_RUNTIME_IMPORT_MAP: Readonly<Record<TPluginRuntimeShimSpecifier, string>>;
|
|
1008
1261
|
|
|
1009
|
-
export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobilePluginApi, type IMobilePluginRegistration, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
|
|
1262
|
+
export { type IAdminPageDefinition, type IFieldRendererDefinition, type IMenuItemDefinition, type IMobileHostRequest, type IMobileHostResponse, type IMobileHostServices, type IMobileHostUploadFile, type IMobileHostUploadRequest, type IMobilePluginApi, type IMobilePluginRegistration, type IMobilePluginStorage, type IPluginApi, type IPluginFeatureFlag, type IPluginFieldRendererProps, type IPluginHealthCheck, type IPluginLock, type IPluginLockEntry, type IPluginLockMigration, type IPluginLockMobileEntry, type IPluginPageModal, type IPluginRealtimePublisher, type IPluginRealtimeTopic, type IPluginRegistration, type IPluginRegistry, type IPluginRelease, type IPluginSettingViewItem, type IPluginSettingsView, type IPluginStylePage, type IPluginStyleProps, IPluginSyncEntry, type IRealtimeTransport, type IRegistryReleaseRef, type IRegistrySignatureBlock, type IResourceUsage, type IRichTextEditorAdapter, type IRichTextEditorAdapterOptions, type IRichTextEditorValue, type IStyleDefinition, type IUsePluginRealtimeOptions, type IUsePluginRealtimeResult, MOBILE_RENDERER_VERSION, PLUGIN_API_VERSION, PLUGIN_REGISTRY_CHANNELS, PLUGIN_RUNTIME_GLOBAL_KEY, PLUGIN_RUNTIME_IMPORT_MAP, PLUGIN_RUNTIME_SHIM_BASE_PATH, PLUGIN_RUNTIME_SHIM_SPECIFIERS, type TMobileHostMethod, type TMobileHostPermission, type TMobileHostPermissionState, type TPluginRegistryChannel, type TPluginRuntimeShimSpecifier, type TRealtimeTransportFactory, assertCmsCompatibility, assertPluginApiVersion, assertPluginVersionSemantics, buildPluginRuntimeShimPath, compareSemver, defineMobilePlugin, definePlugin, definePluginRealtimeTopic, getMobileHostServices, isMobileRendererCompatible, isPluginApiCompatible, isPluginRuntimeShimSpecifier, parseSemver, satisfiesSemverRange, setMobileHostServices, usePluginRealtime };
|
package/dist/plugin-sdk/index.js
CHANGED
|
@@ -39,16 +39,19 @@ __export(plugin_sdk_exports, {
|
|
|
39
39
|
isMobileRendererCompatible: () => isMobileRendererCompatible,
|
|
40
40
|
isPluginApiCompatible: () => isPluginApiCompatible,
|
|
41
41
|
isPluginRuntimeShimSpecifier: () => isPluginRuntimeShimSpecifier,
|
|
42
|
+
matchPluginSyncEntries: () => matchPluginSyncEntries,
|
|
43
|
+
parseInlineRich: () => parseInlineRich,
|
|
42
44
|
parseSemver: () => parseSemver,
|
|
43
45
|
satisfiesSemverRange: () => satisfiesSemverRange,
|
|
44
46
|
setMobileHostServices: () => setMobileHostServices,
|
|
47
|
+
stripHtmlToText: () => stripHtmlToText,
|
|
45
48
|
usePluginRealtime: () => usePluginRealtime
|
|
46
49
|
});
|
|
47
50
|
module.exports = __toCommonJS(plugin_sdk_exports);
|
|
48
51
|
|
|
49
52
|
// src/plugin-sdk/version.ts
|
|
50
|
-
var PLUGIN_API_VERSION = "0.
|
|
51
|
-
var MOBILE_RENDERER_VERSION = "0.
|
|
53
|
+
var PLUGIN_API_VERSION = "0.2.0";
|
|
54
|
+
var MOBILE_RENDERER_VERSION = "0.4.0";
|
|
52
55
|
var SEMVER_REGEX = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/;
|
|
53
56
|
function parseSemver(version) {
|
|
54
57
|
const match = SEMVER_REGEX.exec(version);
|
|
@@ -187,6 +190,37 @@ function assertPluginVersionSemantics(prevVersion, nextVersion, options) {
|
|
|
187
190
|
// src/plugin-sdk/registry.ts
|
|
188
191
|
var PLUGIN_REGISTRY_CHANNELS = ["stable", "beta", "nightly", "test"];
|
|
189
192
|
|
|
193
|
+
// src/plugin-sdk/sync-map.ts
|
|
194
|
+
function matchPluginSyncEntries(entries, tags) {
|
|
195
|
+
if (!entries?.length || tags.length === 0) {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const seen = /* @__PURE__ */ new Set();
|
|
199
|
+
const keys = [];
|
|
200
|
+
for (const entry of entries) {
|
|
201
|
+
if (!entry.tags?.length || !Array.isArray(entry.queryKey)) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const matched = tags.some((tag) => entry.tags.some((pattern) => tagMatchesPattern(tag, pattern)));
|
|
205
|
+
if (!matched) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
const serialized = JSON.stringify(entry.queryKey);
|
|
209
|
+
if (seen.has(serialized)) {
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
seen.add(serialized);
|
|
213
|
+
keys.push(entry.queryKey.slice());
|
|
214
|
+
}
|
|
215
|
+
return keys;
|
|
216
|
+
}
|
|
217
|
+
function tagMatchesPattern(tag, pattern) {
|
|
218
|
+
if (pattern.endsWith("*")) {
|
|
219
|
+
return tag.startsWith(pattern.slice(0, -1));
|
|
220
|
+
}
|
|
221
|
+
return tag === pattern;
|
|
222
|
+
}
|
|
223
|
+
|
|
190
224
|
// src/registry/styles.registry.ts
|
|
191
225
|
var BASE_STYLE_REGISTRY = {
|
|
192
226
|
// ===== auth =====
|
|
@@ -381,6 +415,141 @@ function getMobileHostServices() {
|
|
|
381
415
|
return registeredHostServices;
|
|
382
416
|
}
|
|
383
417
|
|
|
418
|
+
// src/content/inlineFormat.ts
|
|
419
|
+
var HTML_ENTITIES = {
|
|
420
|
+
"&": "&",
|
|
421
|
+
"<": "<",
|
|
422
|
+
">": ">",
|
|
423
|
+
""": '"',
|
|
424
|
+
"'": "'",
|
|
425
|
+
"'": "'",
|
|
426
|
+
" ": " ",
|
|
427
|
+
"/": "/",
|
|
428
|
+
"/": "/"
|
|
429
|
+
};
|
|
430
|
+
function decodeEntities(value) {
|
|
431
|
+
if (!value.includes("&")) return value;
|
|
432
|
+
return value.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
|
|
433
|
+
}
|
|
434
|
+
function looksLikeJson(trimmed) {
|
|
435
|
+
const first = trimmed[0];
|
|
436
|
+
if (first !== "{" && first !== "[") return false;
|
|
437
|
+
try {
|
|
438
|
+
JSON.parse(trimmed);
|
|
439
|
+
return true;
|
|
440
|
+
} catch {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
var SEPARATOR_TAGS = /* @__PURE__ */ new Set([
|
|
445
|
+
"br",
|
|
446
|
+
"p",
|
|
447
|
+
"div",
|
|
448
|
+
"li",
|
|
449
|
+
"ul",
|
|
450
|
+
"ol",
|
|
451
|
+
"h1",
|
|
452
|
+
"h2",
|
|
453
|
+
"h3",
|
|
454
|
+
"h4",
|
|
455
|
+
"h5",
|
|
456
|
+
"h6",
|
|
457
|
+
"blockquote",
|
|
458
|
+
"tr",
|
|
459
|
+
"section",
|
|
460
|
+
"article",
|
|
461
|
+
"header",
|
|
462
|
+
"footer",
|
|
463
|
+
"pre"
|
|
464
|
+
]);
|
|
465
|
+
var TAG_RE = /<\/?([a-z][a-z0-9]*)\b([^>]*)>/gi;
|
|
466
|
+
var HREF_RE = /href\s*=\s*(?:"([^"]*)"|'([^']*)')/i;
|
|
467
|
+
function extractHref(attrs) {
|
|
468
|
+
const match = HREF_RE.exec(attrs);
|
|
469
|
+
return (match?.[1] ?? match?.[2] ?? "").trim();
|
|
470
|
+
}
|
|
471
|
+
function formatKey(node) {
|
|
472
|
+
return `${node.bold ? 1 : 0}|${node.italic ? 1 : 0}|${node.underline ? 1 : 0}|${node.href ?? ""}`;
|
|
473
|
+
}
|
|
474
|
+
function parseInlineRich(value) {
|
|
475
|
+
if (value == null) return [];
|
|
476
|
+
const str = String(value);
|
|
477
|
+
if (str === "") return [];
|
|
478
|
+
const trimmed = str.trim();
|
|
479
|
+
if (looksLikeJson(trimmed)) return [{ text: str }];
|
|
480
|
+
if (!str.includes("<")) {
|
|
481
|
+
const text = decodeEntities(str);
|
|
482
|
+
return text === "" ? [] : [{ text }];
|
|
483
|
+
}
|
|
484
|
+
const raw = [];
|
|
485
|
+
let bold = 0;
|
|
486
|
+
let italic = 0;
|
|
487
|
+
let underline = 0;
|
|
488
|
+
const hrefStack = [];
|
|
489
|
+
const pushText = (segment) => {
|
|
490
|
+
if (segment === "") return;
|
|
491
|
+
raw.push({
|
|
492
|
+
text: segment,
|
|
493
|
+
...bold > 0 ? { bold: true } : {},
|
|
494
|
+
...italic > 0 ? { italic: true } : {},
|
|
495
|
+
...underline > 0 ? { underline: true } : {},
|
|
496
|
+
...hrefStack.length > 0 ? { href: hrefStack[hrefStack.length - 1] } : {}
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
let lastIndex = 0;
|
|
500
|
+
let match;
|
|
501
|
+
TAG_RE.lastIndex = 0;
|
|
502
|
+
while ((match = TAG_RE.exec(str)) !== null) {
|
|
503
|
+
pushText(str.slice(lastIndex, match.index));
|
|
504
|
+
lastIndex = TAG_RE.lastIndex;
|
|
505
|
+
const isClose = match[0].charAt(1) === "/";
|
|
506
|
+
const tag = match[1].toLowerCase();
|
|
507
|
+
const attrs = match[2] ?? "";
|
|
508
|
+
if (tag === "b" || tag === "strong") {
|
|
509
|
+
bold = isClose ? Math.max(0, bold - 1) : bold + 1;
|
|
510
|
+
} else if (tag === "i" || tag === "em") {
|
|
511
|
+
italic = isClose ? Math.max(0, italic - 1) : italic + 1;
|
|
512
|
+
} else if (tag === "u") {
|
|
513
|
+
underline = isClose ? Math.max(0, underline - 1) : underline + 1;
|
|
514
|
+
} else if (tag === "a") {
|
|
515
|
+
if (isClose) {
|
|
516
|
+
hrefStack.pop();
|
|
517
|
+
} else {
|
|
518
|
+
hrefStack.push(extractHref(attrs));
|
|
519
|
+
}
|
|
520
|
+
} else if (SEPARATOR_TAGS.has(tag)) {
|
|
521
|
+
pushText(" ");
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
pushText(str.slice(lastIndex));
|
|
525
|
+
const merged = [];
|
|
526
|
+
for (const node of raw) {
|
|
527
|
+
const prev = merged[merged.length - 1];
|
|
528
|
+
if (prev && formatKey(prev) === formatKey(node)) {
|
|
529
|
+
prev.text += node.text;
|
|
530
|
+
} else {
|
|
531
|
+
merged.push({ ...node });
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
for (const node of merged) {
|
|
535
|
+
node.text = decodeEntities(node.text).replace(/\s+/g, " ");
|
|
536
|
+
}
|
|
537
|
+
if (merged.length > 0) {
|
|
538
|
+
merged[0].text = merged[0].text.replace(/^\s+/, "");
|
|
539
|
+
merged[merged.length - 1].text = merged[merged.length - 1].text.replace(/\s+$/, "");
|
|
540
|
+
}
|
|
541
|
+
return merged.filter((node) => node.text !== "");
|
|
542
|
+
}
|
|
543
|
+
function stripHtmlToText(value) {
|
|
544
|
+
if (!value || typeof value !== "string") return value ?? "";
|
|
545
|
+
const trimmed = value.trim();
|
|
546
|
+
if (looksLikeJson(trimmed)) return value;
|
|
547
|
+
if (!/[<&]/.test(value)) return value;
|
|
548
|
+
let out = value.replace(/<br\s*\/?>/gi, " ").replace(/<\/(p|div|li|h[1-6]|tr|blockquote)>/gi, " ").replace(/<[^>]+>/g, "");
|
|
549
|
+
out = out.replace(/&[a-zA-Z#0-9]+;/g, (entity) => HTML_ENTITIES[entity.toLowerCase()] ?? entity);
|
|
550
|
+
return out.replace(/\s+/g, " ").trim();
|
|
551
|
+
}
|
|
552
|
+
|
|
384
553
|
// src/plugin-sdk/realtime.ts
|
|
385
554
|
var import_react = require("react");
|
|
386
555
|
var DEFAULT_ENDPOINT = "/api/plugins/events";
|
|
@@ -570,8 +739,11 @@ var PLUGIN_RUNTIME_IMPORT_MAP = Object.freeze(
|
|
|
570
739
|
isMobileRendererCompatible,
|
|
571
740
|
isPluginApiCompatible,
|
|
572
741
|
isPluginRuntimeShimSpecifier,
|
|
742
|
+
matchPluginSyncEntries,
|
|
743
|
+
parseInlineRich,
|
|
573
744
|
parseSemver,
|
|
574
745
|
satisfiesSemverRange,
|
|
575
746
|
setMobileHostServices,
|
|
747
|
+
stripHtmlToText,
|
|
576
748
|
usePluginRealtime
|
|
577
749
|
});
|