@zachariaz/strapi-plugin-experience-context 0.0.0-stage → 0.1.0-dev.2
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 +21 -0
- package/README.md +86 -2
- package/dist/_chunks/en-8ms9Hfxr.mjs +27 -0
- package/dist/_chunks/en-yERKDiB0.js +27 -0
- package/dist/admin/index.js +464 -0
- package/dist/admin/index.mjs +448 -0
- package/dist/admin/src/api/client.d.ts +13 -0
- package/dist/admin/src/api/types.d.ts +93 -0
- package/dist/admin/src/api/useInspect.d.ts +3 -0
- package/dist/admin/src/components/BlockMarkers.d.ts +12 -0
- package/dist/admin/src/components/ExperienceModal.d.ts +28 -0
- package/dist/admin/src/components/HeaderBadge.d.ts +19 -0
- package/dist/admin/src/components/Initializer.d.ts +5 -0
- package/dist/admin/src/components/ModalTrigger.d.ts +10 -0
- package/dist/admin/src/contentManagerHooks/editView.d.ts +7 -0
- package/dist/admin/src/index.d.ts +17 -0
- package/dist/admin/src/pluginId.d.ts +2 -0
- package/dist/admin/src/utils/dzSlots.d.ts +16 -0
- package/dist/admin/src/utils/labels.d.ts +30 -0
- package/dist/admin/src/utils/markers.d.ts +12 -0
- package/dist/admin/src/utils/modal.d.ts +10 -0
- package/dist/admin/src/utils/targets.d.ts +12 -0
- package/dist/server/index.js +3780 -0
- package/dist/server/index.mjs +3781 -0
- package/dist/server/src/admin-api/access.d.ts +40 -0
- package/dist/server/src/admin-api/inspect.d.ts +132 -0
- package/dist/server/src/admin-api/mark.d.ts +9 -0
- package/dist/server/src/block-keys/index.d.ts +16 -0
- package/dist/server/src/block-keys/middleware.d.ts +17 -0
- package/dist/server/src/block-keys/stamp.d.ts +55 -0
- package/dist/server/src/block-keys/store.d.ts +33 -0
- package/dist/server/src/block-keys/targets.d.ts +43 -0
- package/dist/server/src/bootstrap.d.ts +16 -0
- package/dist/server/src/changes.d.ts +80 -0
- package/dist/server/src/config/index.d.ts +67 -0
- package/dist/server/src/constants.d.ts +18 -0
- package/dist/server/src/content-types/index.d.ts +309 -0
- package/dist/server/src/controllers/admin.d.ts +10 -0
- package/dist/server/src/controllers/experience.d.ts +15 -0
- package/dist/server/src/controllers/index.d.ts +16 -0
- package/dist/server/src/destroy.d.ts +5 -0
- package/dist/server/src/index.d.ts +441 -0
- package/dist/server/src/integrity/index.d.ts +34 -0
- package/dist/server/src/integrity/orphans.d.ts +40 -0
- package/dist/server/src/mcp/index.d.ts +2 -0
- package/dist/server/src/mcp/operations.d.ts +815 -0
- package/dist/server/src/mcp/permissions.d.ts +56 -0
- package/dist/server/src/mcp/tools.d.ts +59 -0
- package/dist/server/src/model/content.d.ts +32 -0
- package/dist/server/src/model/mapping.d.ts +90 -0
- package/dist/server/src/model/records.d.ts +132 -0
- package/dist/server/src/model/store.d.ts +44 -0
- package/dist/server/src/model/target.d.ts +40 -0
- package/dist/server/src/policies/index.d.ts +4 -0
- package/dist/server/src/rbac/index.d.ts +24 -0
- package/dist/server/src/read-path/editor.d.ts +28 -0
- package/dist/server/src/read-path/gate.d.ts +26 -0
- package/dist/server/src/read-path/index.d.ts +12 -0
- package/dist/server/src/read-path/loader.d.ts +31 -0
- package/dist/server/src/read-path/middleware.d.ts +32 -0
- package/dist/server/src/read-path/payload.d.ts +34 -0
- package/dist/server/src/read-path/populate.d.ts +6 -0
- package/dist/server/src/register.d.ts +14 -0
- package/dist/server/src/registry/index.d.ts +29 -0
- package/dist/server/src/registry/unomi.d.ts +53 -0
- package/dist/server/src/routes/index.d.ts +25 -0
- package/dist/server/src/services/index.d.ts +79 -0
- package/package.json +140 -4
- package/scripts/experience-smoke.mjs +430 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Solteq
|
|
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,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# strapi-plugin-experience-context
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A read-only Strapi Experience Manager extension for inspecting and simulating context-aware content authored through MCP / agentic workflows. The CMS stores semantic concepts, audience annotations and experiment alternatives; the storefront resolves supplied context with the same package the editor uses. It is not a segmentation, rules or journey engine. Replaces the archived personalization POC (no migration).
|
|
4
|
+
|
|
5
|
+
Packages in this repo:
|
|
6
|
+
|
|
7
|
+
| Package | Where | What |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `@zachariaz/strapi-plugin-experience-context` | repo root, plugin id `experience-context` | Strapi v5 plugin: data model, `_experience` read path, MCP tools, read-only Content Manager inspection |
|
|
10
|
+
| `@zachariaz/experience-context-core` | [SolteqExperienceCommerce/experience-context-core](https://github.com/SolteqExperienceCommerce/experience-context-core) | shared contract: types, ids, resolver, HMAC assignment, explanation, validation, Reactionary adapter, fixtures |
|
|
11
|
+
|
|
12
|
+
Plan: `docs/experience-context-plan.md` in strapi-experience-commerce-project. Interfaces: [`docs/integration-contract.md`](docs/integration-contract.md). Agent guide and layout: [`CLAUDE.md`](CLAUDE.md).
|
|
13
|
+
|
|
14
|
+
## Install (app)
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// config/plugins.ts
|
|
18
|
+
import registry from './experience-registry';
|
|
19
|
+
import presets from './experience-presets';
|
|
20
|
+
|
|
21
|
+
export default () => ({
|
|
22
|
+
'experience-context': { enabled: true, config: { registry, presets } },
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
- `contentTypes` (optional): types whose page and `content`-zone `zone.*` blocks can be mapped (default: home, landing-page, pdp, product, category, collection, category-listing).
|
|
27
|
+
- `registry`: `{ audiences, traits, affinities, concepts }`, each `{ id, label, description? }[]`. content-variants segments with an `externalId` are added as `audience/<slug>`; experiments come from the plugin. Unknown ids are warnings.
|
|
28
|
+
- `presets`: `{ name, context }[]` for the simulator; real-looking identifiers are rejected at startup (P1).
|
|
29
|
+
- `roles` (optional, default `false`): `true` provisions the add-on admin roles below at startup (additive: creates missing roles, adds missing plugin actions, never removes anything).
|
|
30
|
+
- `unomi` (optional): `{ url, username?, password?, scope?, ttlSeconds?, timeoutMs? }` reads the segment definitions of a live Unomi (`GET <url>/segments`, definitions only, never profiles) into the registry: `audience.<slug>` → `audience/<slug>`, `affinity.<vocabulary>.<slug>.<band>` → affinity concept `<vocabulary>/<slug>`; other segments are skipped. Cached `ttlSeconds` (default 300); an unreachable Unomi logs one warning and the last known definitions and the static registry still answer. The static registry wins on labels. Empty `url` = off.
|
|
31
|
+
|
|
32
|
+
Both `@zachariaz/strapi-plugin-experience-context` and `@zachariaz/experience-context-core` must be installed.
|
|
33
|
+
|
|
34
|
+
## Data model
|
|
35
|
+
|
|
36
|
+
Hidden, plugin-owned types: `annotation` (concepts of a page or block), `variation` (one row per section member: the default, or a variation with `targetAudiences` ANY / `traits` ALL / `affinities` ALL band-or-higher, or an experiment outcome; `status` active/inactive, `priority`, `validity`), `experiment` (key, outcomes, control, status, validity, winner, externalId), `change` (append-only audit with actor, source and `correlationId`). Apps get one hidden field: `blockKey` on `zone.*` blocks.
|
|
37
|
+
|
|
38
|
+
## Read path
|
|
39
|
+
|
|
40
|
+
`GET /api/<type>?withExperience=true` with a content-API token holding `plugin::experience-context.experience.read` adds `_experience` (contract v2): `{ v: 2, concepts, experiments }` on the document (experiments include per-outcome `blockKeys`) and `{ v: 2, concepts?, variation? }` on mapped blocks. Inactive and orphaned mappings are not sent. `Cache-Control: private, no-store`. Never for Public; without the flag the response is unchanged. Webhook event `experience.update` `{ targets: [{ uid, documentId, locale }], experiments: [...] }` after every mapping change.
|
|
41
|
+
|
|
42
|
+
## MCP tools (the only write path)
|
|
43
|
+
|
|
44
|
+
`experience_describe_target`, `experience_list_registry`, `experience_list_content_variants`, `experience_list_changes`, `experience_create_content_variant`, `experience_update_content_variant`, `experience_associate_variant_with_audience`, `experience_set_experiment`, `experience_associate_variant_with_experiment`, `experience_conclude_experiment`, `experience_annotate_content_with_concepts`, `experience_validate_mapping`, `experience_explain_variant_resolution`, `experience_remove_mapping`, `experience_backfill_block_keys`.
|
|
45
|
+
|
|
46
|
+
`experience_list_content_variants` lists this plugin's block variations (which `zone.*` block a section shows per audience or experiment outcome). Per-entry content variants (one entry, other copy per segment) come from the content-variants plugin (`variants_list_entry_variants`).
|
|
47
|
+
|
|
48
|
+
`experience_list_changes` reads the change log (`experience_changes`), newest first: action, entity, page, section, variation, block, experiment, actor, source, reason, `correlationId` and the before/after records. Filters: page (`targetUid`, `targetDocumentId`, `locale`), `sectionKey`, `variantKey`, `blockKey`, `experimentKey`, `entity`, `action`, `actor`, `source`, `correlationId`, `since`/`until`; paging with `limit` (max 200) and `beforeId`. Needs only the read permission. Example, everything one orchestration run changed:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{ "name": "experience_list_changes", "arguments": { "correlationId": "story-home-hero-3-audiences", "includeValues": false } }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Permissions (RBAC)
|
|
55
|
+
|
|
56
|
+
Humans and agents get access the same way: admin actions under Settings → Roles (people) or Settings → API Tokens → admin token (agents) → Plugins → **Experience Context**. An admin token never exceeds its owner's roles, and its permissions are a frozen snapshot: re-save it after installing or upgrading the plugin.
|
|
57
|
+
|
|
58
|
+
| Action | Allows |
|
|
59
|
+
|---|---|
|
|
60
|
+
| `read` | Content Manager badge and modal, Experience Builder simulator, admin routes, MCP read tools (describe, list, validate, explain) |
|
|
61
|
+
| `variations.write` | audience variations and concept annotations: create/update variant, associate with audience, annotate concepts, remove variation/section/annotation |
|
|
62
|
+
| `experiments.write` | declare, start, pause and conclude experiments, map blocks to outcomes, remove experiments; also any variation call that touches experiment content |
|
|
63
|
+
| `maintenance` | `experience_backfill_block_keys` |
|
|
64
|
+
|
|
65
|
+
Each write action implies `read`. A tool is offered to an MCP session when the token holds one of its actions; a call that needs more (e.g. `create_content_variant` with an experiment outcome) is refused with a message naming the missing permission. Changes are logged with the actor `mcp:token:<tokenId>/user:<ownerId>`.
|
|
66
|
+
|
|
67
|
+
Add-on roles (`roles: true`), given next to a user's base role (Strapi unions roles):
|
|
68
|
+
|
|
69
|
+
| Role (code) | Actions |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Experience Viewer (`experience-context-viewer`) | `read` |
|
|
72
|
+
| Experience Editor (`experience-context-editor`) | `read`, `variations.write` |
|
|
73
|
+
| Experience Manager (`experience-context-manager`) | all four |
|
|
74
|
+
|
|
75
|
+
The `?withExperience=true` read path is a separate content-API permission (`experience.read`), see Read path above. Full-access content-API tokens hold it too: give the storefront a custom token.
|
|
76
|
+
|
|
77
|
+
> Strapi MCP creates and maps content alternatives. If the customer context you need (audience, trait, affinity, experiment) does not exist, find or create it with Unomi MCP first, then reference its id in Strapi. Never describe customer conditions in Strapi.
|
|
78
|
+
|
|
79
|
+
Smoke test: `MCP_ACCESS_TOKEN=… STOREFRONT_TOKEN=… npx experience-smoke` (see the script header).
|
|
80
|
+
|
|
81
|
+
## Admin
|
|
82
|
+
|
|
83
|
+
Read-only: a header badge and DZ block markers in the Content Manager edit view open a modal with About / Intended for / Experiment / Fallback / Created via / Validation per block. Admin routes (`/experience-context/registry`, `/presets`, `/inspect/:uid/:documentId`, `POST /explain`) need any of the plugin's actions (`read` or a write action); `editor.attach` serves Experience Builder.
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
See [`CLAUDE.md`](CLAUDE.md). Nothing is published to npm from a machine; test locally through yalc (`scripts/local-dev.sh`).
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const en = {
|
|
2
|
+
"experience-context.plugin.name": "Experience Context",
|
|
3
|
+
"experience-context.header.title": "Experience",
|
|
4
|
+
"experience-context.header.sections": "{count, plural, one {# section} other {# sections}}",
|
|
5
|
+
"experience-context.header.variations": "{count, plural, one {# variation} other {# variations}}",
|
|
6
|
+
"experience-context.header.experiments.running": "{count, plural, one {# experiment running} other {# experiments running}}",
|
|
7
|
+
"experience-context.header.experiments": "{count, plural, one {# experiment (not running)} other {# experiments (not running)}}",
|
|
8
|
+
"experience-context.header.concepts": "{count, plural, one {# concept} other {# concepts}}",
|
|
9
|
+
"experience-context.header.orphaned": "{count} orphaned",
|
|
10
|
+
"experience-context.header.errors": "{count, plural, one {# validation error} other {# validation errors}}",
|
|
11
|
+
"experience-context.header.open": "Open experience details",
|
|
12
|
+
"experience-context.zone.count": "{count, plural, =0 {No mapped blocks} one {# mapped block} other {# mapped blocks}}",
|
|
13
|
+
"experience-context.modal.title": "Experience (read-only)",
|
|
14
|
+
"experience-context.modal.tab.blocks": "Blocks",
|
|
15
|
+
"experience-context.modal.tab.raw": "Raw JSON",
|
|
16
|
+
"experience-context.modal.page-concepts": "Page is about",
|
|
17
|
+
"experience-context.modal.empty": "No experience mappings on this document.",
|
|
18
|
+
"experience-context.modal.orphaned.title": "Orphaned mappings",
|
|
19
|
+
"experience-context.modal.orphaned.help": "Their block is no longer in the draft, so they are not sent. They apply again if the block comes back.",
|
|
20
|
+
"experience-context.modal.changes": "Last changes",
|
|
21
|
+
"experience-context.modal.error": "Could not load the experience mappings.",
|
|
22
|
+
"experience-context.modal.readonly": "Read-only. Variations, audiences and experiments are authored through the MCP tools.",
|
|
23
|
+
"experience-context.modal.close": "Close"
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
en as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const en = {
|
|
4
|
+
"experience-context.plugin.name": "Experience Context",
|
|
5
|
+
"experience-context.header.title": "Experience",
|
|
6
|
+
"experience-context.header.sections": "{count, plural, one {# section} other {# sections}}",
|
|
7
|
+
"experience-context.header.variations": "{count, plural, one {# variation} other {# variations}}",
|
|
8
|
+
"experience-context.header.experiments.running": "{count, plural, one {# experiment running} other {# experiments running}}",
|
|
9
|
+
"experience-context.header.experiments": "{count, plural, one {# experiment (not running)} other {# experiments (not running)}}",
|
|
10
|
+
"experience-context.header.concepts": "{count, plural, one {# concept} other {# concepts}}",
|
|
11
|
+
"experience-context.header.orphaned": "{count} orphaned",
|
|
12
|
+
"experience-context.header.errors": "{count, plural, one {# validation error} other {# validation errors}}",
|
|
13
|
+
"experience-context.header.open": "Open experience details",
|
|
14
|
+
"experience-context.zone.count": "{count, plural, =0 {No mapped blocks} one {# mapped block} other {# mapped blocks}}",
|
|
15
|
+
"experience-context.modal.title": "Experience (read-only)",
|
|
16
|
+
"experience-context.modal.tab.blocks": "Blocks",
|
|
17
|
+
"experience-context.modal.tab.raw": "Raw JSON",
|
|
18
|
+
"experience-context.modal.page-concepts": "Page is about",
|
|
19
|
+
"experience-context.modal.empty": "No experience mappings on this document.",
|
|
20
|
+
"experience-context.modal.orphaned.title": "Orphaned mappings",
|
|
21
|
+
"experience-context.modal.orphaned.help": "Their block is no longer in the draft, so they are not sent. They apply again if the block comes back.",
|
|
22
|
+
"experience-context.modal.changes": "Last changes",
|
|
23
|
+
"experience-context.modal.error": "Could not load the experience mappings.",
|
|
24
|
+
"experience-context.modal.readonly": "Read-only. Variations, audiences and experiments are authored through the MCP tools.",
|
|
25
|
+
"experience-context.modal.close": "Close"
|
|
26
|
+
};
|
|
27
|
+
exports.default = en;
|
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const designSystem = require("@strapi/design-system");
|
|
5
|
+
const icons = require("@strapi/icons");
|
|
6
|
+
const strapiAdmin = require("@strapi/content-manager/strapi-admin");
|
|
7
|
+
const reactIntl = require("react-intl");
|
|
8
|
+
const admin = require("@strapi/strapi/admin");
|
|
9
|
+
const reactDom = require("react-dom");
|
|
10
|
+
const reactRouterDom = require("react-router-dom");
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== "default") {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
|
29
|
+
const pluginId = "experience-context";
|
|
30
|
+
const Initializer = ({ setPlugin }) => {
|
|
31
|
+
const ref = React.useRef(setPlugin);
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
ref.current(pluginId);
|
|
34
|
+
}, []);
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
const cache = /* @__PURE__ */ new Map();
|
|
38
|
+
const INSPECT_TTL_MS = 5e3;
|
|
39
|
+
const inspectUrl = (uid, documentId) => `/${pluginId}/inspect/${encodeURIComponent(uid)}${documentId ? `/${encodeURIComponent(documentId)}` : ""}`;
|
|
40
|
+
function fetchInspect(get, uid, documentId, locale, now = Date.now()) {
|
|
41
|
+
const key = `${uid}\0${documentId ?? ""}\0${locale ?? ""}`;
|
|
42
|
+
const hit = cache.get(key);
|
|
43
|
+
if (hit && now - hit.at < INSPECT_TTL_MS) return hit.promise;
|
|
44
|
+
const promise = get(inspectUrl(uid, documentId), locale ? { params: { locale } } : void 0).then(({ data }) => data?.data);
|
|
45
|
+
promise.catch(() => cache.delete(key));
|
|
46
|
+
cache.set(key, { at: now, promise });
|
|
47
|
+
return promise;
|
|
48
|
+
}
|
|
49
|
+
function useInspect(uid, documentId, locale, skip = false) {
|
|
50
|
+
const { get } = admin.useFetchClient();
|
|
51
|
+
const [data, setData] = React__namespace.useState(void 0);
|
|
52
|
+
React__namespace.useEffect(() => {
|
|
53
|
+
if (skip || !uid) {
|
|
54
|
+
setData(null);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
fetchInspect(get, uid, documentId, locale).then((view) => !cancelled && setData(view)).catch(() => !cancelled && setData(null));
|
|
59
|
+
return () => {
|
|
60
|
+
cancelled = true;
|
|
61
|
+
};
|
|
62
|
+
}, [get, uid, documentId, locale, skip]);
|
|
63
|
+
return data;
|
|
64
|
+
}
|
|
65
|
+
const hasAnything = (s) => Boolean(s && (s.sections || s.concepts || s.annotatedBlocks || s.orphaned || s.experiments.length));
|
|
66
|
+
function headerParts(s, pluginId2) {
|
|
67
|
+
const parts = [];
|
|
68
|
+
if (s.sections) {
|
|
69
|
+
parts.push({ id: `${pluginId2}.header.sections`, defaultMessage: "{count, plural, one {# section} other {# sections}}", values: { count: s.sections } });
|
|
70
|
+
}
|
|
71
|
+
if (s.variations) {
|
|
72
|
+
parts.push({ id: `${pluginId2}.header.variations`, defaultMessage: "{count, plural, one {# variation} other {# variations}}", values: { count: s.variations } });
|
|
73
|
+
}
|
|
74
|
+
const running = s.experiments.filter((e) => e.running).length;
|
|
75
|
+
if (running) {
|
|
76
|
+
parts.push({ id: `${pluginId2}.header.experiments.running`, defaultMessage: "{count, plural, one {# experiment running} other {# experiments running}}", values: { count: running } });
|
|
77
|
+
} else if (s.experiments.length) {
|
|
78
|
+
parts.push({ id: `${pluginId2}.header.experiments`, defaultMessage: "{count, plural, one {# experiment (not running)} other {# experiments (not running)}}", values: { count: s.experiments.length } });
|
|
79
|
+
}
|
|
80
|
+
if (s.concepts) {
|
|
81
|
+
parts.push({ id: `${pluginId2}.header.concepts`, defaultMessage: "{count, plural, one {# concept} other {# concepts}}", values: { count: s.concepts } });
|
|
82
|
+
}
|
|
83
|
+
if (s.orphaned) parts.push({ id: `${pluginId2}.header.orphaned`, defaultMessage: "{count} orphaned", values: { count: s.orphaned } });
|
|
84
|
+
if (s.errors) {
|
|
85
|
+
parts.push({ id: `${pluginId2}.header.errors`, defaultMessage: "{count, plural, one {# validation error} other {# validation errors}}", values: { count: s.errors } });
|
|
86
|
+
}
|
|
87
|
+
return parts;
|
|
88
|
+
}
|
|
89
|
+
function markerText(card) {
|
|
90
|
+
switch (card.role) {
|
|
91
|
+
case "default":
|
|
92
|
+
return "Default";
|
|
93
|
+
case "variation":
|
|
94
|
+
return "Variation";
|
|
95
|
+
case "outcome":
|
|
96
|
+
return `Outcome ${card.experiment?.outcome ?? ""}`.trim();
|
|
97
|
+
default:
|
|
98
|
+
return "Concepts";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function markerLabel(card) {
|
|
102
|
+
const parts = [card.heading];
|
|
103
|
+
if (card.sectionKey) parts.push(`section ${card.sectionKey}`);
|
|
104
|
+
if (card.intendedFor.length) parts.push(`intended for ${card.intendedFor.join(", ")}`);
|
|
105
|
+
if (card.experiment) parts.push(`experiment ${card.experiment.key} / ${card.experiment.outcome}`);
|
|
106
|
+
if (card.status && card.status !== "active") parts.push(card.status);
|
|
107
|
+
return parts.join(" · ");
|
|
108
|
+
}
|
|
109
|
+
function cardRows(card) {
|
|
110
|
+
return [
|
|
111
|
+
{ label: "About", value: card.about.length ? card.about.join(" · ") : "–" },
|
|
112
|
+
{ label: "Intended for", value: card.intendedFor.length ? card.intendedFor.join(" · ") : "–" },
|
|
113
|
+
{
|
|
114
|
+
label: "Experiment",
|
|
115
|
+
value: card.experiment ? [`${card.experiment.key} · outcome ${card.experiment.outcome}`, card.experiment.split ? `split ${card.experiment.split}` : null].filter(Boolean).join(" · ") : "–"
|
|
116
|
+
},
|
|
117
|
+
{ label: "Fallback", value: card.fallback ? card.fallback.label : "–" },
|
|
118
|
+
{
|
|
119
|
+
label: "Created via",
|
|
120
|
+
value: card.createdVia ? [card.createdVia.label, card.createdVia.date, card.createdVia.correlationId ? `correlation ${card.createdVia.correlationId}` : null].filter(Boolean).join(" · ") : "–"
|
|
121
|
+
},
|
|
122
|
+
{ label: "Validation", value: card.validation.length ? card.validation.join(" ") : "–" }
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
function isTargetType(options) {
|
|
126
|
+
return Boolean(options?.[pluginId]?.target);
|
|
127
|
+
}
|
|
128
|
+
const CONTENT_ZONE = "content";
|
|
129
|
+
const UID = /^api::[a-z0-9-]+\.[a-z0-9-]+$/;
|
|
130
|
+
function parseCmPath(pathname) {
|
|
131
|
+
const m = pathname.match(/\/content-manager\/(collection-types|single-types)\/([^/?#]+)(?:\/([^/?#]+))?/);
|
|
132
|
+
if (!m) return null;
|
|
133
|
+
const uid = decodeURIComponent(m[2]);
|
|
134
|
+
if (!UID.test(uid)) return null;
|
|
135
|
+
const documentId = m[3] && m[3] !== "create" ? decodeURIComponent(m[3]) : null;
|
|
136
|
+
return { collectionType: m[1], uid, documentId };
|
|
137
|
+
}
|
|
138
|
+
function localeFromSearch(search) {
|
|
139
|
+
const params = new URLSearchParams(search);
|
|
140
|
+
const locale = params.get("plugins[i18n][locale]");
|
|
141
|
+
return locale && /^[A-Za-z0-9-]{1,35}$/.test(locale) ? locale : null;
|
|
142
|
+
}
|
|
143
|
+
function modalCards(view, focusKey) {
|
|
144
|
+
const byKey = view.byBlockKey ?? {};
|
|
145
|
+
if (focusKey) {
|
|
146
|
+
const card = byKey[focusKey];
|
|
147
|
+
return { cards: card ? [card] : [], orphaned: [], raw: card ?? null };
|
|
148
|
+
}
|
|
149
|
+
const cards = Object.values(byKey).sort((a, b) => (a.index ?? 1e9) - (b.index ?? 1e9));
|
|
150
|
+
return {
|
|
151
|
+
cards,
|
|
152
|
+
orphaned: view.orphaned ?? [],
|
|
153
|
+
raw: { page: view.page ?? null, blocks: byKey, orphaned: view.orphaned ?? [], experiments: view.experiments ?? [], validation: view.validation ?? null }
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const Row = ({ label, children }) => /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "baseline", children: [
|
|
157
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", style: { minWidth: "8rem" }, children: label }),
|
|
158
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children })
|
|
159
|
+
] });
|
|
160
|
+
const BlockCard = ({ card }) => {
|
|
161
|
+
const rows = cardRows(card);
|
|
162
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, hasRadius: true, borderColor: "neutral200", background: "neutral0", "data-testid": "experience-card", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
|
|
164
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", children: card.heading }),
|
|
165
|
+
card.title && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: card.title }),
|
|
166
|
+
card.status === "inactive" && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { children: "Inactive" }),
|
|
167
|
+
card.status === "orphaned" && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "warning100", textColor: "warning700", children: "Orphaned" }),
|
|
168
|
+
card.experiment?.status === "running" && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "success100", textColor: "success700", children: "Running experiment" })
|
|
169
|
+
] }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: rows.map(
|
|
171
|
+
(row) => row.label === "Validation" ? /* @__PURE__ */ jsxRuntime.jsx(Row, { label: row.label.toUpperCase(), children: card.validation.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: "–" }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "ul", children: card.validation.map((line, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", textColor: line.startsWith("✗") ? "danger600" : line.startsWith("⚠") ? "warning600" : "success600", children: line }) }, i)) }) }, row.label) : /* @__PURE__ */ jsxRuntime.jsx(Row, { label: row.label.toUpperCase(), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "omega", children: row.value }) }, row.label)
|
|
172
|
+
) })
|
|
173
|
+
] }) });
|
|
174
|
+
};
|
|
175
|
+
const ModalBody = ({ view, focusKey }) => {
|
|
176
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
177
|
+
const { cards, orphaned, raw } = modalCards(view, focusKey);
|
|
178
|
+
const concepts = view.page?.concepts ?? [];
|
|
179
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.Root, { defaultValue: "blocks", children: [
|
|
180
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Tabs.List, { "aria-label": "Experience views", children: [
|
|
181
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "blocks", children: formatMessage({ id: `${pluginId}.modal.tab.blocks`, defaultMessage: "Blocks" }) }),
|
|
182
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Trigger, { value: "raw", children: formatMessage({ id: `${pluginId}.modal.tab.raw`, defaultMessage: "Raw JSON" }) })
|
|
183
|
+
] }),
|
|
184
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "blocks", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 4, paddingTop: 4, children: [
|
|
185
|
+
!focusKey && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: [
|
|
186
|
+
formatMessage({ id: `${pluginId}.modal.page-concepts`, defaultMessage: "Page is about" }),
|
|
187
|
+
": ",
|
|
188
|
+
concepts.length ? concepts.join(" · ") : "–"
|
|
189
|
+
] }),
|
|
190
|
+
cards.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral500", children: formatMessage({ id: `${pluginId}.modal.empty`, defaultMessage: "No experience mappings on this document." }) }),
|
|
191
|
+
cards.map((card) => /* @__PURE__ */ jsxRuntime.jsx(BlockCard, { card }, card.blockKey)),
|
|
192
|
+
orphaned.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
|
|
193
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", children: formatMessage({ id: `${pluginId}.modal.orphaned.title`, defaultMessage: "Orphaned mappings" }) }),
|
|
194
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({
|
|
195
|
+
id: `${pluginId}.modal.orphaned.help`,
|
|
196
|
+
defaultMessage: "Their block is no longer in the draft, so they are not sent. They apply again if the block comes back."
|
|
197
|
+
}) }),
|
|
198
|
+
orphaned.map((card) => /* @__PURE__ */ jsxRuntime.jsx(BlockCard, { card }, card.blockKey))
|
|
199
|
+
] }),
|
|
200
|
+
!focusKey && (view.changes?.length ?? 0) > 0 && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { children: [
|
|
201
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: formatMessage({ id: `${pluginId}.modal.changes`, defaultMessage: "Last changes" }) }),
|
|
202
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "ul", children: view.changes.map((c, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Typography, { variant: "pi", children: [
|
|
203
|
+
c.createdAt ? `${String(c.createdAt).replace("T", " ").slice(0, 16)} UTC` : "?",
|
|
204
|
+
" · ",
|
|
205
|
+
c.action,
|
|
206
|
+
" ",
|
|
207
|
+
c.entity,
|
|
208
|
+
c.sectionKey ? ` ${c.sectionKey}${c.variantKey ? `/${c.variantKey}` : ""}` : "",
|
|
209
|
+
c.experimentKey ? ` (${c.experimentKey})` : "",
|
|
210
|
+
c.actor ? ` by ${c.actor}` : "",
|
|
211
|
+
c.correlationId ? ` · correlation ${c.correlationId}` : ""
|
|
212
|
+
] }) }, i)) })
|
|
213
|
+
] })
|
|
214
|
+
] }) }),
|
|
215
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Content, { value: "raw", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { paddingTop: 4, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "pre", padding: 4, background: "neutral100", hasRadius: true, style: { overflow: "auto", maxHeight: "60vh", fontSize: "12px" }, children: JSON.stringify(raw, null, 2) }) }) })
|
|
216
|
+
] });
|
|
217
|
+
};
|
|
218
|
+
const ExperienceModal = ({ open, onClose, uid, documentId, locale, view: given, focusKey, title }) => {
|
|
219
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
220
|
+
const { get } = admin.useFetchClient();
|
|
221
|
+
const [view, setView] = React__namespace.useState(given);
|
|
222
|
+
const [failed, setFailed] = React__namespace.useState(false);
|
|
223
|
+
React__namespace.useEffect(() => {
|
|
224
|
+
if (!open) return;
|
|
225
|
+
if (given) {
|
|
226
|
+
setView(given);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let cancelled = false;
|
|
230
|
+
fetchInspect(get, uid, documentId, locale).then((v) => !cancelled && setView(v)).catch(() => !cancelled && setFailed(true));
|
|
231
|
+
return () => {
|
|
232
|
+
cancelled = true;
|
|
233
|
+
};
|
|
234
|
+
}, [open, given, get, uid, documentId, locale]);
|
|
235
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Root, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Content, { onClick: (e) => e.stopPropagation(), "data-testid": "experience-modal", children: [
|
|
236
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Title, { children: title ?? formatMessage({ id: `${pluginId}.modal.title`, defaultMessage: "Experience (read-only)" }) }) }),
|
|
237
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Body, { children: [
|
|
238
|
+
failed && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage({ id: `${pluginId}.modal.error`, defaultMessage: "Could not load the experience mappings." }) }),
|
|
239
|
+
!failed && !view && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral500", children: "…" }),
|
|
240
|
+
view && /* @__PURE__ */ jsxRuntime.jsx(ModalBody, { view, focusKey })
|
|
241
|
+
] }),
|
|
242
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Footer, { children: [
|
|
243
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral600", children: formatMessage({ id: `${pluginId}.modal.readonly`, defaultMessage: "Read-only. Variations, audiences and experiments are authored through the MCP tools." }) }),
|
|
244
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Close, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({ id: `${pluginId}.modal.close`, defaultMessage: "Close" }) }) })
|
|
245
|
+
] })
|
|
246
|
+
] }) });
|
|
247
|
+
};
|
|
248
|
+
function headerText(summary, formatMessage) {
|
|
249
|
+
const title = formatMessage({ id: `${pluginId}.header.title`, defaultMessage: "Experience" });
|
|
250
|
+
const parts = headerParts(summary, pluginId).map(({ id, defaultMessage, values }) => formatMessage({ id, defaultMessage }, values));
|
|
251
|
+
return [title, ...parts].join(" · ");
|
|
252
|
+
}
|
|
253
|
+
const HeaderBadgeContent = ({ summary, view }) => {
|
|
254
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
255
|
+
const [open, setOpen] = React__namespace.useState(false);
|
|
256
|
+
const text = headerText(summary, formatMessage);
|
|
257
|
+
const target = view?.target;
|
|
258
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
259
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
260
|
+
designSystem.Button,
|
|
261
|
+
{
|
|
262
|
+
variant: "tertiary",
|
|
263
|
+
size: "S",
|
|
264
|
+
startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Eye, { "aria-hidden": true }),
|
|
265
|
+
onClick: () => setOpen(true),
|
|
266
|
+
disabled: !target,
|
|
267
|
+
"aria-haspopup": "dialog",
|
|
268
|
+
"aria-label": `${text}. ${formatMessage({ id: `${pluginId}.header.open`, defaultMessage: "Open experience details" })}`,
|
|
269
|
+
title: text,
|
|
270
|
+
"data-testid": "experience-header-badge",
|
|
271
|
+
style: { maxWidth: "44rem" },
|
|
272
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { display: "block", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: text })
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
open && target && /* @__PURE__ */ jsxRuntime.jsx(ExperienceModal, { open: true, onClose: () => setOpen(false), uid: target.uid, documentId: target.documentId, locale: view?.locale, view })
|
|
276
|
+
] });
|
|
277
|
+
};
|
|
278
|
+
const ExperienceHeaderAction = ({ model, documentId, document: document2 }) => {
|
|
279
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
280
|
+
const { edit } = strapiAdmin.unstable_useDocumentLayout(model);
|
|
281
|
+
const target = isTargetType(edit?.options);
|
|
282
|
+
const locale = document2?.locale ?? localeFromSearch(window.location.search);
|
|
283
|
+
const view = useInspect(model, documentId ?? document2?.documentId, locale, !target || documentId === "create");
|
|
284
|
+
const summary = view?.summary;
|
|
285
|
+
if (!target || !hasAnything(summary)) return null;
|
|
286
|
+
return {
|
|
287
|
+
label: formatMessage({ id: `${pluginId}.header.title`, defaultMessage: "Experience" }),
|
|
288
|
+
// The `_status` slot renders any node in the header.
|
|
289
|
+
_status: {
|
|
290
|
+
message: /* @__PURE__ */ jsxRuntime.jsx(HeaderBadgeContent, { summary, view })
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
const ModalTrigger = ({
|
|
295
|
+
children,
|
|
296
|
+
label,
|
|
297
|
+
...modal
|
|
298
|
+
}) => {
|
|
299
|
+
const [open, setOpen] = React__namespace.useState(false);
|
|
300
|
+
const stop = (e) => e.stopPropagation();
|
|
301
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { onClick: stop, onKeyDown: stop, onPointerDown: stop, style: { display: "inline-flex" }, children: [
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
303
|
+
"button",
|
|
304
|
+
{
|
|
305
|
+
type: "button",
|
|
306
|
+
"aria-label": label,
|
|
307
|
+
"aria-haspopup": "dialog",
|
|
308
|
+
onClick: () => setOpen(true),
|
|
309
|
+
style: { all: "unset", cursor: "pointer", display: "inline-flex" },
|
|
310
|
+
"data-testid": "experience-open-modal",
|
|
311
|
+
children
|
|
312
|
+
}
|
|
313
|
+
),
|
|
314
|
+
open && /* @__PURE__ */ jsxRuntime.jsx(ExperienceModal, { open: true, onClose: () => setOpen(false), ...modal })
|
|
315
|
+
] });
|
|
316
|
+
};
|
|
317
|
+
function markersFor(blockKeys, byBlockKey) {
|
|
318
|
+
return blockKeys.map((key) => key && byBlockKey?.[key] || null);
|
|
319
|
+
}
|
|
320
|
+
const KEY_SEPARATOR = "";
|
|
321
|
+
function encodeKeys(blocks) {
|
|
322
|
+
if (!Array.isArray(blocks)) return "";
|
|
323
|
+
return blocks.map((b) => typeof b?.blockKey === "string" ? b.blockKey : "").join(KEY_SEPARATOR);
|
|
324
|
+
}
|
|
325
|
+
function decodeKeys(encoded) {
|
|
326
|
+
if (!encoded) return [];
|
|
327
|
+
return encoded.split(KEY_SEPARATOR).map((k) => k || null);
|
|
328
|
+
}
|
|
329
|
+
const SLOT_ATTR = "data-experience-context-marker";
|
|
330
|
+
function findZoneList(anchor) {
|
|
331
|
+
let node = anchor;
|
|
332
|
+
for (let depth = 0; node && depth < 12; depth += 1) {
|
|
333
|
+
const list = node.querySelector(":scope > ol");
|
|
334
|
+
if (list) return list;
|
|
335
|
+
node = node.parentElement;
|
|
336
|
+
}
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
function slotFor(li) {
|
|
340
|
+
const header = li.querySelector("h3");
|
|
341
|
+
if (!header) return null;
|
|
342
|
+
const existing = header.querySelector(`:scope > [${SLOT_ATTR}]`);
|
|
343
|
+
if (existing) return existing;
|
|
344
|
+
const slot = document.createElement("span");
|
|
345
|
+
slot.setAttribute(SLOT_ATTR, "");
|
|
346
|
+
slot.style.display = "inline-flex";
|
|
347
|
+
slot.style.alignItems = "center";
|
|
348
|
+
slot.style.paddingInline = "4px";
|
|
349
|
+
const trigger = header.querySelector(":scope > button");
|
|
350
|
+
header.insertBefore(slot, trigger ? trigger.nextSibling : header.firstChild);
|
|
351
|
+
return slot;
|
|
352
|
+
}
|
|
353
|
+
function zoneSlots(anchor) {
|
|
354
|
+
const list = findZoneList(anchor);
|
|
355
|
+
if (!list) return [];
|
|
356
|
+
return Array.from(list.children).map((li) => slotFor(li));
|
|
357
|
+
}
|
|
358
|
+
const COLORS = {
|
|
359
|
+
default: ["neutral150", "neutral700"],
|
|
360
|
+
variation: ["primary100", "primary700"],
|
|
361
|
+
outcome: ["success100", "success700"],
|
|
362
|
+
concepts: ["secondary100", "secondary700"]
|
|
363
|
+
};
|
|
364
|
+
const BlockMarker = ({ card, view }) => {
|
|
365
|
+
const label = markerLabel(card);
|
|
366
|
+
const [bg, fg] = card.status === "inactive" ? ["neutral150", "neutral500"] : COLORS[card.role];
|
|
367
|
+
const Icon = card.role === "outcome" ? icons.ChartPie : card.role === "concepts" ? icons.PriceTag : icons.Eye;
|
|
368
|
+
const badge = /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { "aria-label": label, "data-testid": "experience-marker", backgroundColor: bg, textColor: fg, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, style: { whiteSpace: "nowrap" }, children: [
|
|
369
|
+
/* @__PURE__ */ jsxRuntime.jsx(Icon, { width: "1rem", height: "1rem", "aria-hidden": true }),
|
|
370
|
+
markerText(card),
|
|
371
|
+
card.variantKey && card.role !== "default" ? ` "${card.variantKey}"` : ""
|
|
372
|
+
] }) }) });
|
|
373
|
+
if (!view?.target) return badge;
|
|
374
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ModalTrigger, { label: `${label}. Open details`, uid: view.target.uid, documentId: view.target.documentId, locale: view.locale, view, focusKey: card.blockKey, children: badge });
|
|
375
|
+
};
|
|
376
|
+
const BlockMarkers = () => {
|
|
377
|
+
const { formatMessage } = reactIntl.useIntl();
|
|
378
|
+
const location = reactRouterDom.useLocation();
|
|
379
|
+
const path = parseCmPath(location.pathname);
|
|
380
|
+
const locale = localeFromSearch(location.search);
|
|
381
|
+
const view = useInspect(path?.uid, path?.documentId, locale, !path);
|
|
382
|
+
const encoded = admin.useForm("experience-context/BlockMarkers", (state) => encodeKeys(state.values?.[CONTENT_ZONE]));
|
|
383
|
+
const keys = React__namespace.useMemo(() => decodeKeys(encoded), [encoded]);
|
|
384
|
+
const markers = React__namespace.useMemo(() => markersFor(keys, view?.byBlockKey), [keys, view]);
|
|
385
|
+
const anchor = React__namespace.useRef(null);
|
|
386
|
+
const [slots, setSlots] = React__namespace.useState([]);
|
|
387
|
+
const active = Boolean(view?.target);
|
|
388
|
+
const refresh = React__namespace.useCallback(() => {
|
|
389
|
+
const next = active ? zoneSlots(anchor.current) : [];
|
|
390
|
+
setSlots((prev) => prev.length === next.length && prev.every((s, i) => s === next[i]) ? prev : next);
|
|
391
|
+
}, [active]);
|
|
392
|
+
React__namespace.useLayoutEffect(refresh);
|
|
393
|
+
React__namespace.useEffect(() => {
|
|
394
|
+
const list = findZoneList(anchor.current);
|
|
395
|
+
if (!active || !list || typeof MutationObserver === "undefined") return;
|
|
396
|
+
const observer = new MutationObserver(refresh);
|
|
397
|
+
observer.observe(list, { childList: true, subtree: true });
|
|
398
|
+
return () => observer.disconnect();
|
|
399
|
+
}, [active, refresh]);
|
|
400
|
+
const count = markers.filter(Boolean).length;
|
|
401
|
+
if (!view?.target) return /* @__PURE__ */ jsxRuntime.jsx("span", { ref: anchor });
|
|
402
|
+
const label = formatMessage(
|
|
403
|
+
{
|
|
404
|
+
id: `${pluginId}.zone.count`,
|
|
405
|
+
defaultMessage: "{count, plural, =0 {No mapped blocks} one {# mapped block} other {# mapped blocks}}"
|
|
406
|
+
},
|
|
407
|
+
{ count }
|
|
408
|
+
);
|
|
409
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { ref: anchor, style: { display: "inline-flex" }, children: [
|
|
410
|
+
/* @__PURE__ */ jsxRuntime.jsx(ModalTrigger, { label: `${label}. Open details`, uid: view.target.uid, documentId: view.target.documentId, locale: view.locale, view, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { "aria-label": label, "data-testid": "experience-zone-count", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, style: { whiteSpace: "nowrap" }, children: [
|
|
411
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Eye, { width: "1rem", height: "1rem", "aria-hidden": true }),
|
|
412
|
+
label
|
|
413
|
+
] }) }) }),
|
|
414
|
+
markers.map((card, i) => card && slots[i] ? reactDom.createPortal(/* @__PURE__ */ jsxRuntime.jsx(BlockMarker, { card, view }), slots[i], `m-${i}`) : null)
|
|
415
|
+
] });
|
|
416
|
+
};
|
|
417
|
+
const withMarkers = (field) => {
|
|
418
|
+
if (field.name !== CONTENT_ZONE || field.type !== "dynamiczone") return field;
|
|
419
|
+
return {
|
|
420
|
+
...field,
|
|
421
|
+
labelAction: field.labelAction ? /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 1, children: [
|
|
422
|
+
field.labelAction,
|
|
423
|
+
/* @__PURE__ */ jsxRuntime.jsx(BlockMarkers, {})
|
|
424
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(BlockMarkers, {})
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
const mutateEditViewHook = (args) => {
|
|
428
|
+
const { layout } = args;
|
|
429
|
+
if (!isTargetType(layout?.options)) return args;
|
|
430
|
+
return {
|
|
431
|
+
...args,
|
|
432
|
+
layout: {
|
|
433
|
+
...layout,
|
|
434
|
+
layout: layout.layout.map((panel) => panel.map((row) => row.map(withMarkers)))
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
const index = {
|
|
439
|
+
register(app) {
|
|
440
|
+
app.registerPlugin({
|
|
441
|
+
id: pluginId,
|
|
442
|
+
initializer: Initializer,
|
|
443
|
+
isReady: false,
|
|
444
|
+
name: pluginId
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
bootstrap(app) {
|
|
448
|
+
const contentManager = app.getPlugin("content-manager");
|
|
449
|
+
if (contentManager) {
|
|
450
|
+
const cm = contentManager.apis;
|
|
451
|
+
cm.addDocumentHeaderAction([ExperienceHeaderAction]);
|
|
452
|
+
}
|
|
453
|
+
app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
|
|
454
|
+
},
|
|
455
|
+
// English only for now.
|
|
456
|
+
async registerTrads({ locales }) {
|
|
457
|
+
const en = (await Promise.resolve().then(() => require("../_chunks/en-yERKDiB0.js"))).default;
|
|
458
|
+
return locales.map((locale) => ({
|
|
459
|
+
locale,
|
|
460
|
+
data: locale === "en" ? en : {}
|
|
461
|
+
}));
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
module.exports = index;
|