@obelism/content 0.16.0 → 0.18.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/README.md +92 -0
- package/dist/bin/content.js +32 -1
- package/dist/bridge.d.mts +16 -3
- package/dist/bridge.d.mts.map +1 -1
- package/dist/bridge.d.ts +16 -3
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.global.js +3 -3
- package/dist/bridge.js +90 -14
- package/dist/bridge.mjs +90 -14
- package/dist/index.d.mts +64 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +64 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -1
- package/dist/index.mjs +83 -2
- package/dist/{preview-mpwfmnla.js → preview-ijk3ixwb.js} +17 -0
- package/dist/{preview-h7rwp06v.mjs → preview-jcmxxj92.mjs} +15 -1
- package/dist/site.js +5 -0
- package/dist/site.mjs +5 -0
- package/dist/{types-m3j4tltp.d.ts → types-mtjco3a5.d.ts} +40 -2
- package/dist/types-mtjco3a5.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/types-m3j4tltp.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -155,6 +155,26 @@ getContentBridge({ pagePath: (path, locale) => `/${locale}/${path}` })
|
|
|
155
155
|
await bridge.createPage('/pricing', 'Our plans, for agencies') // or your own UI
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
On a product route, mark the Shopify product the page shows. When the
|
|
159
|
+
product has no product page yet (nothing on the page is `editable(entry)`),
|
|
160
|
+
the box offers **Add a product page**: the CMS makes a draft of the space's
|
|
161
|
+
product page type for it (its handle as slug, in the `products` folder)
|
|
162
|
+
and the page reloads, now finding it. The page list opens product pages at the environment's product path (Settings →
|
|
163
|
+
Preview URL in the CMS, `/products/{handle}` by default), or at your own
|
|
164
|
+
`productPath`:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { editable, editableProduct } from '@obelism/content'
|
|
168
|
+
|
|
169
|
+
// app/products/[handle]/page.tsx: the store's product, and its page if any.
|
|
170
|
+
;<main {...editableProduct(product)} {...editable(productPage)}>
|
|
171
|
+
…
|
|
172
|
+
</main>
|
|
173
|
+
|
|
174
|
+
getContentBridge({ productPath: (handle, locale) => `/${locale}/p/${handle}` })
|
|
175
|
+
await bridge.createProductPage() // or your own UI; bridge.product says which
|
|
176
|
+
```
|
|
177
|
+
|
|
158
178
|
There the box also switches between **Prompt** and **Form**. Form shows the
|
|
159
179
|
CMS's own form for the page — or for the entry around the selected block —
|
|
160
180
|
right in the box: the fields, and blocks as cards to open and add,
|
|
@@ -295,6 +315,33 @@ const xml = sitemapXml(pages, {
|
|
|
295
315
|
})
|
|
296
316
|
```
|
|
297
317
|
|
|
318
|
+
## Links
|
|
319
|
+
|
|
320
|
+
A `link` field goes to a page of the space, to any address, or (with
|
|
321
|
+
`products: true`) to a product of the space's Shopify store, each with an optional query and anchor. It is
|
|
322
|
+
delivered as `Link`: the page's `id`, `title`, `slug` and `path` (never its
|
|
323
|
+
fields), the `url`, or the `product` (`{ id, handle }`) with its product
|
|
324
|
+
page as `entry` (`null` when it has none), plus `query` and `hash` without
|
|
325
|
+
their `?` and `#`. A link to a page that isn't published is `null`. Where a
|
|
326
|
+
page's path lives on your site is your routing, so `linkHref` takes it as
|
|
327
|
+
`url` (default `/<path>`), a product's address as `product` (default
|
|
328
|
+
`/products/<handle>`), and adds the query and hash:
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
import { linkHref } from '@obelism/content'
|
|
332
|
+
|
|
333
|
+
;<a
|
|
334
|
+
href={
|
|
335
|
+
linkHref(button.link, {
|
|
336
|
+
url: (path) => `/${locale}/${path}`,
|
|
337
|
+
product: ({ handle }) => `/${locale}/products/${handle}`,
|
|
338
|
+
}) ?? undefined
|
|
339
|
+
}
|
|
340
|
+
>
|
|
341
|
+
{button.label}
|
|
342
|
+
</a>
|
|
343
|
+
```
|
|
344
|
+
|
|
298
345
|
## A/B tests and feature flags
|
|
299
346
|
|
|
300
347
|
Any blocks field can hold the built-in improve block (`ImproveBlock`,
|
|
@@ -319,6 +366,50 @@ const blocks = layout.flatMap((block) => {
|
|
|
319
366
|
variant, else the first one, when the option is `null` (the test isn't
|
|
320
367
|
active or the visitor isn't in it) or has no variant.
|
|
321
368
|
|
|
369
|
+
## Shopify
|
|
370
|
+
|
|
371
|
+
A `shopify` field holds a collection or product of the Shopify store
|
|
372
|
+
connected to the space (Settings in Obelism Content), as `ShopifyItem`:
|
|
373
|
+
`{ id, handle }`. Content stores only that, so fetch prices, stock and images
|
|
374
|
+
live from Shopify's Storefront API with the store's domain and Storefront
|
|
375
|
+
token (Settings → Copy as .env):
|
|
376
|
+
|
|
377
|
+
```ts
|
|
378
|
+
import { fetchShopifyCollection } from '@obelism/content'
|
|
379
|
+
|
|
380
|
+
// A productGrid block: { heading, collection, columns }.
|
|
381
|
+
const collection = await fetchShopifyCollection(block.collection, {
|
|
382
|
+
shop: process.env.SHOPIFY_STORE_DOMAIN!,
|
|
383
|
+
storefrontToken: process.env.SHOPIFY_STOREFRONT_TOKEN!,
|
|
384
|
+
first: 12,
|
|
385
|
+
country: 'NL', // optional: the market's prices
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
collection?.products.map((product) => ({
|
|
389
|
+
href: `/products/${product.handle}`,
|
|
390
|
+
title: product.title,
|
|
391
|
+
price: product.priceRange.minVariantPrice,
|
|
392
|
+
image: product.featuredImage,
|
|
393
|
+
}))
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
A page type with a unique product field is a product page type: one page
|
|
397
|
+
per product, for what the store doesn't hold. On your product route, find
|
|
398
|
+
the page by the product's id, and render the store's product alone when there
|
|
399
|
+
is none:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
const productPage = await content.getFirstEntry({
|
|
403
|
+
contentType: 'productPage',
|
|
404
|
+
fields: { product: product.id }, // gid://shopify/Product/…
|
|
405
|
+
})
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
`fetchShopifyProducts(items, options)` does the same for a product field
|
|
409
|
+
(one item or a list), in the field's order. Both leave out what the store no
|
|
410
|
+
longer has. A Hydrogen or Liquid site can use the `id` with its own
|
|
411
|
+
Storefront queries instead.
|
|
412
|
+
|
|
322
413
|
## CLI
|
|
323
414
|
|
|
324
415
|
Start a site's repository on a space, in its root:
|
|
@@ -372,6 +463,7 @@ locale, rich text as a document), and `| null` when empty:
|
|
|
372
463
|
| select | the options' values, `'a' \| 'b'` (a list when multiple) |
|
|
373
464
|
| asset | `Asset` (a list when multiple) |
|
|
374
465
|
| reference | the allowed entry types or their `EntryStub`s (a list when multiple) |
|
|
466
|
+
| link | `Link` |
|
|
375
467
|
| blocks | a list of the allowed block types and `ImproveBlock` |
|
|
376
468
|
| richtext | `RichTextDocument` |
|
|
377
469
|
| json | `unknown` |
|
package/dist/bin/content.js
CHANGED
|
@@ -146,6 +146,31 @@ const buildExamples = (model, improve)=>{
|
|
|
146
146
|
improveBlock(field.allowedBlocks, depth + 1)
|
|
147
147
|
] : blocks;
|
|
148
148
|
}
|
|
149
|
+
case 'link':
|
|
150
|
+
return {
|
|
151
|
+
type: 'entry',
|
|
152
|
+
entry: {
|
|
153
|
+
id: 'entry_example',
|
|
154
|
+
title: 'Example page',
|
|
155
|
+
slug: 'example',
|
|
156
|
+
path: 'example'
|
|
157
|
+
},
|
|
158
|
+
query: null,
|
|
159
|
+
hash: null
|
|
160
|
+
};
|
|
161
|
+
case 'shopify':
|
|
162
|
+
{
|
|
163
|
+
const item = field.resource === 'collection' ? {
|
|
164
|
+
id: 'gid://shopify/Collection/1',
|
|
165
|
+
handle: 'example-collection'
|
|
166
|
+
} : {
|
|
167
|
+
id: 'gid://shopify/Product/1',
|
|
168
|
+
handle: 'example-product'
|
|
169
|
+
};
|
|
170
|
+
return field.multiple ? [
|
|
171
|
+
item
|
|
172
|
+
] : item;
|
|
173
|
+
}
|
|
149
174
|
case 'json':
|
|
150
175
|
return {};
|
|
151
176
|
}
|
|
@@ -535,7 +560,9 @@ const SDK_TYPES = [
|
|
|
535
560
|
'Entry',
|
|
536
561
|
'EntryStub',
|
|
537
562
|
'ImproveBlock',
|
|
538
|
-
'
|
|
563
|
+
'Link',
|
|
564
|
+
'RichTextDocument',
|
|
565
|
+
'ShopifyItem'
|
|
539
566
|
];
|
|
540
567
|
// The unions of every entry and block type the file ends with.
|
|
541
568
|
const UNION_NAMES = [
|
|
@@ -607,6 +634,10 @@ const generateTypes = (model)=>{
|
|
|
607
634
|
improve
|
|
608
635
|
]), true);
|
|
609
636
|
}
|
|
637
|
+
case 'link':
|
|
638
|
+
return use('Link');
|
|
639
|
+
case 'shopify':
|
|
640
|
+
return list(use('ShopifyItem'), field.multiple);
|
|
610
641
|
case 'json':
|
|
611
642
|
return 'unknown';
|
|
612
643
|
}
|
package/dist/bridge.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entry } from './index.mjs';
|
|
1
|
+
import { Entry, ShopifyItem } from './index.mjs';
|
|
2
2
|
|
|
3
3
|
type BlockStats = {
|
|
4
4
|
clicks: number;
|
|
@@ -54,6 +54,11 @@ type CreatePageResult = {
|
|
|
54
54
|
path: string;
|
|
55
55
|
url: string;
|
|
56
56
|
};
|
|
57
|
+
type CreateProductPageResult = {
|
|
58
|
+
entryId: string;
|
|
59
|
+
path: string;
|
|
60
|
+
created: boolean;
|
|
61
|
+
};
|
|
57
62
|
type ApplyJsonResult = {
|
|
58
63
|
changed: string[];
|
|
59
64
|
view?: Record<string, unknown> | undefined;
|
|
@@ -73,18 +78,21 @@ type SitePage = {
|
|
|
73
78
|
status: 'draft' | 'published' | 'changed';
|
|
74
79
|
path: string;
|
|
75
80
|
url: string;
|
|
81
|
+
product: ShopifyItem | null;
|
|
76
82
|
};
|
|
77
83
|
type ContentBridge = {
|
|
78
84
|
readonly isEditing: boolean;
|
|
79
85
|
readonly mode: 'editor' | 'site' | null;
|
|
80
86
|
readonly entryId: string | null;
|
|
81
87
|
readonly environment: string | null;
|
|
88
|
+
readonly product: ShopifyItem | null;
|
|
82
89
|
on<E extends BridgeEvent>(event: E, listener: BridgeListener<E>): () => void;
|
|
83
90
|
getState(): BridgeState;
|
|
84
91
|
prompt(prompt: string, options?: {
|
|
85
92
|
uid?: string | null;
|
|
86
93
|
}): Promise<PromptResult>;
|
|
87
94
|
createPage(path: string, prompt: string): Promise<CreatePageResult>;
|
|
95
|
+
createProductPage(product?: ShopifyItem): Promise<CreateProductPageResult>;
|
|
88
96
|
view(options?: {
|
|
89
97
|
uid?: string | null | undefined;
|
|
90
98
|
}): Promise<Record<string, unknown>>;
|
|
@@ -145,6 +153,10 @@ type PromptLabels = {
|
|
|
145
153
|
pageCurrent: string;
|
|
146
154
|
pageDraft: string;
|
|
147
155
|
pageChanged: string;
|
|
156
|
+
addProductPage: string;
|
|
157
|
+
addingProductPage: string;
|
|
158
|
+
addedProductPage: string;
|
|
159
|
+
productPageHint: string;
|
|
148
160
|
};
|
|
149
161
|
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
150
162
|
type PromptBoxOptions = {
|
|
@@ -156,10 +168,11 @@ type BridgeOptions = {
|
|
|
156
168
|
url?: string | undefined;
|
|
157
169
|
prompt?: boolean | PromptBoxOptions | undefined;
|
|
158
170
|
pagePath?: ((path: string, locale: string) => string) | undefined;
|
|
171
|
+
productPath?: ((handle: string, locale: string) => string) | undefined;
|
|
159
172
|
};
|
|
160
173
|
declare const peekContentBridge: () => ContentBridge | null;
|
|
161
|
-
declare const getContentBridge: ({ url, prompt, pagePath, }?: BridgeOptions) => ContentBridge;
|
|
174
|
+
declare const getContentBridge: ({ url, prompt, pagePath, productPath, }?: BridgeOptions) => ContentBridge;
|
|
162
175
|
|
|
163
176
|
export { DEFAULT_PROMPT_LABELS, DEFAULT_STATS_LABELS, INITIAL_STATE, getContentBridge, mountPromptBox, mountStatsOverlay, peekContentBridge };
|
|
164
|
-
export type { ApplyJsonResult, BlockStats, BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, CreatePageResult, FormHandle, FormOptions, PromptBoxOptions, PromptLabels, PromptResult, SitePage, StatsLabels, StatsOverlay };
|
|
177
|
+
export type { ApplyJsonResult, BlockStats, BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, CreatePageResult, CreateProductPageResult, FormHandle, FormOptions, PromptBoxOptions, PromptLabels, PromptResult, SitePage, StatsLabels, StatsOverlay };
|
|
165
178
|
//# sourceMappingURL=bridge.d.mts.map
|
package/dist/bridge.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.mts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAAA,KAAK,UAAU;AACf;AACA;AACA;AACA;AACA;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA,cAAc,oBAAoB,EAAE,WAAW;AAc/C,KAAK,YAAY;AACjB,kBAAkB,QAAQ,CAAC,MAAM,SAAS,UAAU;AACpD;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,MAAM;AAC7C;AACA;AACA,aAAa,OAAO,CAAC,WAAW;AAChC,MAAM,YAAY;;AC5BlB,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ,CAAC,MAAM,SAAS,UAAU;AAC7C;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,gBAAgB;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK,eAAe;AACpB;AACA,WAAW,MAAM;AACjB;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA,KAAK,UAAU;AACf;AACA;AACA,KAAK,QAAQ;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B,8CAA8C,OAAO,CAAC,gBAAgB;AACtE;AACA;AACA,QAAQ,OAAO,CAAC,MAAM;AACtB,uBAAuB,MAAM;AAC7B;AACA,QAAQ,OAAO,CAAC,eAAe;AAC/B,wBAAwB,WAAW,YAAY,WAAW,GAAG,UAAU;AACvE,aAAa,OAAO,CAAC,QAAQ;AAC7B,mBAAmB,QAAQ;AAC3B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;
|
|
1
|
+
{"version":3,"file":"bridge.d.mts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAAA,KAAK,UAAU;AACf;AACA;AACA;AACA;AACA;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA,cAAc,oBAAoB,EAAE,WAAW;AAc/C,KAAK,YAAY;AACjB,kBAAkB,QAAQ,CAAC,MAAM,SAAS,UAAU;AACpD;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,MAAM;AAC7C;AACA;AACA,aAAa,OAAO,CAAC,WAAW;AAChC,MAAM,YAAY;;AC5BlB,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ,CAAC,MAAM,SAAS,UAAU;AAC7C;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,gBAAgB;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK,uBAAuB;AAC5B;AACA;AACA;AACA;AACA,KAAK,eAAe;AACpB;AACA,WAAW,MAAM;AACjB;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA,KAAK,UAAU;AACf;AACA;AACA,KAAK,QAAQ;AACb;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,WAAW;AACxB;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B,8CAA8C,OAAO,CAAC,gBAAgB;AACtE,gCAAgC,WAAW,GAAG,OAAO,CAAC,uBAAuB;AAC7E;AACA;AACA,QAAQ,OAAO,CAAC,MAAM;AACtB,uBAAuB,MAAM;AAC7B;AACA,QAAQ,OAAO,CAAC,eAAe;AAC/B,wBAAwB,WAAW,YAAY,WAAW,GAAG,UAAU;AACvE,aAAa,OAAO,CAAC,QAAQ;AAC7B,mBAAmB,QAAQ;AAC3B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;AC7FxC,KAAK,YAAY;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC;AACA,cAAc,cAAc,QAAQ,QAAQ,UAAU,aAAa,YAAY,gBAAgB;;AC3C/F,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,6CAA6C,aAAa,KAAK,aAAa","names":[]}
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Entry } from './index.js';
|
|
1
|
+
import { Entry, ShopifyItem } from './index.js';
|
|
2
2
|
|
|
3
3
|
type BlockStats = {
|
|
4
4
|
clicks: number;
|
|
@@ -54,6 +54,11 @@ type CreatePageResult = {
|
|
|
54
54
|
path: string;
|
|
55
55
|
url: string;
|
|
56
56
|
};
|
|
57
|
+
type CreateProductPageResult = {
|
|
58
|
+
entryId: string;
|
|
59
|
+
path: string;
|
|
60
|
+
created: boolean;
|
|
61
|
+
};
|
|
57
62
|
type ApplyJsonResult = {
|
|
58
63
|
changed: string[];
|
|
59
64
|
view?: Record<string, unknown> | undefined;
|
|
@@ -73,18 +78,21 @@ type SitePage = {
|
|
|
73
78
|
status: 'draft' | 'published' | 'changed';
|
|
74
79
|
path: string;
|
|
75
80
|
url: string;
|
|
81
|
+
product: ShopifyItem | null;
|
|
76
82
|
};
|
|
77
83
|
type ContentBridge = {
|
|
78
84
|
readonly isEditing: boolean;
|
|
79
85
|
readonly mode: 'editor' | 'site' | null;
|
|
80
86
|
readonly entryId: string | null;
|
|
81
87
|
readonly environment: string | null;
|
|
88
|
+
readonly product: ShopifyItem | null;
|
|
82
89
|
on<E extends BridgeEvent>(event: E, listener: BridgeListener<E>): () => void;
|
|
83
90
|
getState(): BridgeState;
|
|
84
91
|
prompt(prompt: string, options?: {
|
|
85
92
|
uid?: string | null;
|
|
86
93
|
}): Promise<PromptResult>;
|
|
87
94
|
createPage(path: string, prompt: string): Promise<CreatePageResult>;
|
|
95
|
+
createProductPage(product?: ShopifyItem): Promise<CreateProductPageResult>;
|
|
88
96
|
view(options?: {
|
|
89
97
|
uid?: string | null | undefined;
|
|
90
98
|
}): Promise<Record<string, unknown>>;
|
|
@@ -145,6 +153,10 @@ type PromptLabels = {
|
|
|
145
153
|
pageCurrent: string;
|
|
146
154
|
pageDraft: string;
|
|
147
155
|
pageChanged: string;
|
|
156
|
+
addProductPage: string;
|
|
157
|
+
addingProductPage: string;
|
|
158
|
+
addedProductPage: string;
|
|
159
|
+
productPageHint: string;
|
|
148
160
|
};
|
|
149
161
|
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
150
162
|
type PromptBoxOptions = {
|
|
@@ -156,10 +168,11 @@ type BridgeOptions = {
|
|
|
156
168
|
url?: string | undefined;
|
|
157
169
|
prompt?: boolean | PromptBoxOptions | undefined;
|
|
158
170
|
pagePath?: ((path: string, locale: string) => string) | undefined;
|
|
171
|
+
productPath?: ((handle: string, locale: string) => string) | undefined;
|
|
159
172
|
};
|
|
160
173
|
declare const peekContentBridge: () => ContentBridge | null;
|
|
161
|
-
declare const getContentBridge: ({ url, prompt, pagePath, }?: BridgeOptions) => ContentBridge;
|
|
174
|
+
declare const getContentBridge: ({ url, prompt, pagePath, productPath, }?: BridgeOptions) => ContentBridge;
|
|
162
175
|
|
|
163
176
|
export { DEFAULT_PROMPT_LABELS, DEFAULT_STATS_LABELS, INITIAL_STATE, getContentBridge, mountPromptBox, mountStatsOverlay, peekContentBridge };
|
|
164
|
-
export type { ApplyJsonResult, BlockStats, BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, CreatePageResult, FormHandle, FormOptions, PromptBoxOptions, PromptLabels, PromptResult, SitePage, StatsLabels, StatsOverlay };
|
|
177
|
+
export type { ApplyJsonResult, BlockStats, BridgeEvent, BridgeEvents, BridgeListener, BridgeOptions, BridgeState, ContentBridge, CreatePageResult, CreateProductPageResult, FormHandle, FormOptions, PromptBoxOptions, PromptLabels, PromptResult, SitePage, StatsLabels, StatsOverlay };
|
|
165
178
|
//# sourceMappingURL=bridge.d.ts.map
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAAA,KAAK,UAAU;AACf;AACA;AACA;AACA;AACA;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA,cAAc,oBAAoB,EAAE,WAAW;AAc/C,KAAK,YAAY;AACjB,kBAAkB,QAAQ,CAAC,MAAM,SAAS,UAAU;AACpD;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,MAAM;AAC7C;AACA;AACA,aAAa,OAAO,CAAC,WAAW;AAChC,MAAM,YAAY;;AC5BlB,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ,CAAC,MAAM,SAAS,UAAU;AAC7C;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,gBAAgB;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK,eAAe;AACpB;AACA,WAAW,MAAM;AACjB;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA,KAAK,UAAU;AACf;AACA;AACA,KAAK,QAAQ;AACb;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B,8CAA8C,OAAO,CAAC,gBAAgB;AACtE;AACA;AACA,QAAQ,OAAO,CAAC,MAAM;AACtB,uBAAuB,MAAM;AAC7B;AACA,QAAQ,OAAO,CAAC,eAAe;AAC/B,wBAAwB,WAAW,YAAY,WAAW,GAAG,UAAU;AACvE,aAAa,OAAO,CAAC,QAAQ;AAC7B,mBAAmB,QAAQ;AAC3B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sources":["../src/bridge/statsOverlay.ts","../src/bridge/createBridge.ts","../src/bridge/promptBox.ts","../src/bridge.ts"],"mappings":";;AAAA,KAAK,UAAU;AACf;AACA;AACA;AACA;AACA;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA,cAAc,oBAAoB,EAAE,WAAW;AAc/C,KAAK,YAAY;AACjB,kBAAkB,QAAQ,CAAC,MAAM,SAAS,UAAU;AACpD;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,MAAM;AAC7C;AACA;AACA,aAAa,OAAO,CAAC,WAAW;AAChC,MAAM,YAAY;;AC5BlB,KAAK,YAAY;AACjB;AACA,eAAe,KAAK;AACpB;AACA;AACA,WAAW,MAAM;AACjB,eAAe,MAAM;AACrB,YAAY,WAAW;AACvB;AACA,KAAK,WAAW,SAAS,YAAY;AACrC,KAAK,cAAc,WAAW,WAAW,cAAc,YAAY;AACnE,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAW,QAAQ,CAAC,MAAM,SAAS,UAAU;AAC7C;AACA;AACA,KAAK,YAAY;AACjB;AACA;AACA,KAAK,gBAAgB;AACrB;AACA;AACA;AACA;AACA;AACA,KAAK,uBAAuB;AAC5B;AACA;AACA;AACA;AACA,KAAK,eAAe;AACpB;AACA,WAAW,MAAM;AACjB;AACA,KAAK,WAAW;AAChB;AACA;AACA;AACA;AACA,KAAK,UAAU;AACf;AACA;AACA,KAAK,QAAQ;AACb;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,WAAW;AACxB;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,iBAAiB,WAAW,sBAAsB,cAAc;AAChE,gBAAgB,WAAW;AAC3B;AACA;AACA,QAAQ,OAAO,CAAC,YAAY;AAC5B,8CAA8C,OAAO,CAAC,gBAAgB;AACtE,gCAAgC,WAAW,GAAG,OAAO,CAAC,uBAAuB;AAC7E;AACA;AACA,QAAQ,OAAO,CAAC,MAAM;AACtB,uBAAuB,MAAM;AAC7B;AACA,QAAQ,OAAO,CAAC,eAAe;AAC/B,wBAAwB,WAAW,YAAY,WAAW,GAAG,UAAU;AACvE,aAAa,OAAO,CAAC,QAAQ;AAC7B,mBAAmB,QAAQ;AAC3B;AACA,YAAY,OAAO;AACnB,eAAe,OAAO;AACtB;AACA;AACA;AACA;AACA;AAEA,cAAc,aAAa,EAAE,WAAW;;AC7FxC,KAAK,YAAY;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC;AACA,cAAc,cAAc,QAAQ,QAAQ,UAAU,aAAa,YAAY,gBAAgB;;AC3C/F,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,6CAA6C,aAAa,KAAK,aAAa","names":[]}
|
package/dist/bridge.global.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
!/*! Obelism Content bridge (@obelism/content), MIT. https://content.obelism.studio/docs/guides/visual-editor */function(){"use strict";var e;let t="data-cms-uid",r="data-cms-entry",n="cms_environment",
|
|
1
|
+
!/*! Obelism Content bridge (@obelism/content), MIT. https://content.obelism.studio/docs/guides/visual-editor */function(){"use strict";var e;let t="data-cms-uid",r="data-cms-entry",o="data-cms-product",n="cms_environment",a={clicked:"{rate}% clicked",title:"{clickers} of {viewers} visitors of its page clicked it in the last 30 days ({clicks} clicks)"},i=(e,t)=>e.replace(/\{(\w+)\}/g,(e,r)=>r in t?String(t[r]):e),s=`
|
|
2
2
|
:host { all: initial; }
|
|
3
3
|
.layer {
|
|
4
4
|
position: fixed; inset: 0; pointer-events: none;
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
.badge[data-place='beside'] { transform: translateY(-50%); }
|
|
23
23
|
.badge[data-place='above'] { transform: translate(-100%, -100%); }
|
|
24
24
|
.badge:focus-visible { outline: 2px solid rgb(212 130 30); outline-offset: 2px; }
|
|
25
|
-
`,
|
|
25
|
+
`,l=(e,t)=>e.height>=64?{place:"inside",top:Math.max(e.top,0)+8,left:e.right-8}:e.right+8+140<=t?{place:"beside",top:e.top+e.height/2,left:e.right+8}:{place:"above",top:e.top-4,left:e.right},d="obelism-content-bridge",c="#d58a1f",p=(e="")=>`${e}[${t}]{cursor:pointer;transition:outline-color .15s}${e}[${t}]:hover{outline:2px dashed ${c};outline-offset:2px}${e}[${t}][data-cms-selected]{outline:2px solid ${c};outline-offset:2px}`,g={features:[],selectedUid:null,prompting:!1,canUndo:!1,unsaved:!1,saving:!1,publishing:!1,selecting:!1,stats:{},statsVisible:!1},u=()=>{let e={update:new Set,saved:new Set,published:new Set,change:new Set};return{listeners:e,on:(t,r)=>(e[t].add(r),()=>{e[t].delete(r)}),emit(t,r){for(let o of e[t])try{o(r)}catch(e){console.error("[@obelism/content bridge]",e)}}}},h=()=>Promise.reject(Error("Save and publish in the visual editor itself")),b=()=>Promise.reject(Error("Only while signed in to edit on the site")),m={prompt:()=>Promise.reject(Error("Prompts only work inside the visual editor")),createPage:()=>Promise.reject(Error("New pages are made on the site itself")),createProductPage:()=>Promise.reject(Error("Product pages are made on the site itself")),view:b,applyJson:b,openForm:(e,t={})=>(queueMicrotask(()=>t.onError?.("Only while signed in to edit on the site")),{close:()=>{}}),pages:b,openPage:()=>{},undo:()=>{},save:h,publish:h,signOut:()=>{},select:()=>{},setSelecting:()=>{}},f=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0,v=e=>`[${t}="${e.replace(/["\\]/g,"\\$&")}"]`,y=(e,t)=>{let r=u();e.on("saved",()=>r.emit("saved",{})),e.on("published",()=>r.emit("published",{}));let o=!1;return{isEditing:e.isEditing,mode:e.isEditing?"editor":null,entryId:e.entryId,environment:t.get(n),product:null,on:(t,n)=>("update"!==t||o||(o=!0,e.on("update",e=>{let t=e?.entry;t&&r.emit("update",{entry:t,selectedUid:null})})),r.on(t,n)),getState:()=>g,...m,destroy:()=>{}}},x={open:"Edit with a prompt",placeholder:"Describe a change, e.g. “make the heading shorter”",send:"Apply",undo:"Undo",close:"Close",minimize:"Minimize, to see the page",expand:"Expand",scopeEntry:"Whole page",scopeBlock:"Selected block",clearBlock:"Edit the whole page instead",working:"Working on it…",save:"Save",publish:"Publish",saving:"Saving…",publishing:"Publishing…",saved:"Saved as a draft",published:"Published",unsaved:"Unsaved changes",signOut:"Exit editing",viewingDrafts:"Viewing drafts",selectHint:"Click a block to change only that block",newPage:"New page",newPageCancel:"Edit this page instead",newPagePlaceholder:"Describe the new page, e.g. “a pricing page for agencies”",path:"Path",pathPlaceholder:"/pricing",creating:"Writing the page…",created:"Opening the new page…",modes:"Edit with",modePrompt:"Prompt",form:"Form",formTitle:"The content form",formLoading:"Opening the form…",pages:"Pages",pagesSearch:"Find a page",pagesLoading:"Loading pages…",pagesEmpty:"No pages match",pageCurrent:"This page",pageDraft:"Draft",pageChanged:"Changed",addProductPage:"Add a product page",addingProductPage:"Making the product page…",addedProductPage:"Opening the product page…",productPageHint:"This product has no page yet. Add one for what the store doesn’t say."},w={page:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/>',newPage:'<path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M9 15h6"/><path d="M12 18v-6"/>',block:'<rect width="18" height="18" x="3" y="3" rx="2"/><path d="M7 8h10"/><path d="M7 12h6"/>',undo:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 0 11H11"/>',close:'<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',minimize:'<path d="m6 9 6 6 6-6"/>',expand:'<path d="m18 15-6-6-6 6"/>',chevrons:'<path d="m7 15 5 5 5-5"/><path d="m7 9 5-5 5 5"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',check:'<path d="M20 6 9 17l-5-5"/>',send:'<path d="M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z"/><path d="M6 12h16"/>'},k=`
|
|
26
26
|
:host { all: initial; }
|
|
27
27
|
* { box-sizing: border-box; font: inherit; color: inherit; margin: 0; }
|
|
28
28
|
.root {
|
|
@@ -233,4 +233,4 @@ button.chip:disabled { opacity: .5; }
|
|
|
233
233
|
.empty { padding: 8px 12px; color: rgb(var(--theme-foreground-muted-rgb)); }
|
|
234
234
|
.empty.error { color: var(--theme-error); }
|
|
235
235
|
[hidden] { display: none !important; }
|
|
236
|
-
`,k=(e,t,r={},...n)=>{let o=e.createElement(t);for(let t of(Object.assign(o,r),n))o.appendChild("string"==typeof t?e.createTextNode(t):t);return o},E=(e,t)=>{let r=k(e,"span",{className:"icon"});return r.setAttribute("aria-hidden","true"),r.innerHTML=`<svg viewBox="0 0 24 24">${x[t]}</svg>`,r},C=(e,t,r={})=>{let n={...y,...r.labels},o=k(e,"div");o.setAttribute("data-obelism-content-prompt","");let a=o.attachShadow({mode:"open"}),i="site"===t.mode,s=k(e,"span",{textContent:n.open}),l=k(e,"button",{className:"pill",type:"button"},s,k(e,"span",{className:"mark",textContent:"⁜"})),d=k(e,"span",{className:"pill compact"},`${n.viewingDrafts} \xb7 `),c=k(e,"button",{className:"link",type:"button",textContent:n.signOut});d.appendChild(c);let p=k(e,"p",{className:"status"});p.setAttribute("role","status");let g=k(e,"textarea",{placeholder:n.placeholder,rows:1});g.setAttribute("aria-label",n.open);let u=k(e,"div",{className:"form"}),h=E(e,"page"),b=E(e,"block"),m=k(e,"span"),f=k(e,"button",{type:"button",title:n.clearBlock});f.setAttribute("aria-label",n.clearBlock),f.appendChild(E(e,"close"));let v=k(e,"span",{className:"chip scope"},h,b,m,f),x=k(e,"button",{className:"action chip",type:"button"},E(e,"undo"),n.undo),C=t=>{let r=k(e,"button",{type:"button",textContent:t});return r.setAttribute("aria-pressed","false"),r},A=C(n.modePrompt),S=C(n.form),L=k(e,"span",{className:"modes"},A,S);L.setAttribute("role","group"),L.setAttribute("aria-label",n.modes);let N=k(e,"button",{className:"action chip",type:"button"},E(e,"newPage"),n.newPage),U=k(e,"button",{type:"button",title:n.newPageCancel});U.setAttribute("aria-label",n.newPageCancel),U.appendChild(E(e,"close"));let P=k(e,"span",{className:"chip scope"},E(e,"newPage"),k(e,"span",{textContent:n.newPage}),U),I=k(e,"input",{type:"text",placeholder:n.pathPlaceholder,autocomplete:"off",spellcheck:!1}),$=k(e,"label",{className:"path"},k(e,"span",{textContent:n.path}),I),M=k(e,"button",{className:"close icon-button",type:"button",title:n.close},E(e,"close"));M.setAttribute("aria-label",n.close);let O=E(e,"minimize"),T=E(e,"expand"),z=k(e,"button",{className:"icon-button",type:"button"},O,T),j=k(e,"button",{className:"action primary icon-button",type:"submit"},k(e,"span",{className:"visually-hidden",textContent:n.send}),E(e,"send"));j.title=n.send;let R=k(e,"span",{className:"divider"}),D=k(e,"div",{className:"toolbar"},v,P,L,x,N,k(e,"span",{className:"spacer"}),z,M,R,j),F=k(e,"span",{textContent:n.pages}),q=k(e,"button",{className:"chip page-chip",type:"button",title:n.pages},E(e,"page"),F,E(e,"chevrons"));q.setAttribute("aria-haspopup","listbox"),q.setAttribute("aria-expanded","false"),q.setAttribute("aria-controls","obelism-pages");let B=k(e,"input",{type:"text",placeholder:n.pagesSearch,autocomplete:"off",spellcheck:!1});B.setAttribute("role","combobox"),B.setAttribute("aria-label",n.pagesSearch),B.setAttribute("aria-autocomplete","list"),B.setAttribute("aria-expanded","true"),B.setAttribute("aria-controls","obelism-pages");let V=k(e,"ul",{className:"options",id:"obelism-pages"});V.setAttribute("role","listbox"),V.setAttribute("aria-label",n.pages);let Y=k(e,"p",{className:"empty"}),H=k(e,"div",{className:"pages"},k(e,"label",{className:"search"},E(e,"search"),B),V,Y),W=k(e,"span",{className:"unsaved"});W.appendChild(k(e,"span",{className:"dot"})),W.appendChild(e.createTextNode(n.unsaved));let _=k(e,"button",{className:"link",type:"button",textContent:n.signOut}),J=k(e,"button",{className:"action chip",type:"button",textContent:n.save}),X=k(e,"button",{className:"action chip",type:"button",textContent:n.publish}),Z=k(e,"div",{className:"footer"},q,W,k(e,"span",{className:"spacer"}),_,J,X),K=k(e,"form",{className:"panel"},p,$,g,u,D,H,Z),G=k(e,"div",{className:"root"},k(e,"div",{className:"bar"},l,d),K);a.append(k(e,"style",{textContent:w}),G);let Q=!1,ee=!1,et=!1,er=null,en=!1,eo=null,ea=!1,ei=!1,es=null,el=null,ed=null,ec=0,ep=e=>({text:e instanceof Error?e.message:String(e),error:!0}),eg=e=>{let r=e.features.includes("prompt"),o=e.saving||e.publishing,a=e.prompting||o;G.hidden=!r&&!i,l.hidden=Q||!r,d.hidden=r||!i,K.hidden=!Q||!r;let c=i&&e.features.includes("create"),y=i&&null===t.entryId,w=y&&c;c||(et=!1),w&&(et=!0),(et||y||!i)&&(en=!1);let k=Q&&r&&en;k&&!eo?eb():!k&&eo&&em(),s.textContent=w?n.newPage:n.open,U.hidden=w,v.hidden=et,P.hidden=!et,N.hidden=et||en||!c,N.disabled=a,ee&&(ei=!1),$.hidden=!et||ei||ee,I.disabled=a,g.hidden=en||ei||ee,u.hidden=!en||ei||ee,u.classList.toggle("loading",ea),D.hidden=ei,H.hidden=!ei,g.placeholder=et?n.newPagePlaceholder:n.placeholder,m.textContent=e.selectedUid?n.scopeBlock:n.scopeEntry,f.hidden=!e.selectedUid,h.hidden=!!e.selectedUid,b.hidden=!e.selectedUid,L.hidden=!i||et||y||!e.features.includes("form"),A.setAttribute("aria-pressed",String(!en)),S.setAttribute("aria-pressed",String(en)),L.querySelectorAll("button").forEach(e=>{e.disabled=a}),x.hidden=et||!e.canUndo,x.disabled=a,j.hidden=en||ee,R.hidden=en||ee;let E=ee?n.expand:n.minimize;z.title=E,z.setAttribute("aria-label",E),z.setAttribute("aria-expanded",String(!ee)),O.hidden=ee,T.hidden=!ee,j.disabled=a||""===g.value.trim()||et&&""===I.value.trim(),g.disabled=a,J.hidden=!e.features.includes("save")||y,J.disabled=a||!e.unsaved,J.textContent=e.saving?n.saving:n.save,X.hidden=!e.features.includes("publish")||y,X.disabled=a,X.textContent=e.publishing?n.publishing:n.publish,_.hidden=!i,Z.hidden=!i,W.hidden=!e.unsaved,q.hidden=!i,q.setAttribute("aria-expanded",String(ei)),F.textContent=es?.find(({entryId:e})=>e===t.entryId)?.name??n.pages;let C=en&&ea&&!ei,M=e.prompting||C,B=e.prompting?et?n.creating:n.working:C?n.formLoading:er?.text??(!i||et||ei||e.selectedUid?"":n.selectHint);p.textContent=B,p.hidden=!B||ee,p.className=`status${M?" working":""}${!a&&!C&&er?.error?" error":""}`},eu=()=>eg(t.getState()),eh=()=>{g.style.height="auto",g.style.height=`${g.scrollHeight}px`},eb=()=>{ea=!0,u.classList.add("loading");let e=t.openForm(u,{title:n.formTitle,onReady:()=>{eo===e&&(ea=!1,er=null,eu())},onError:t=>{eo===e&&(ea=!1,er={text:t,error:!0},eu())}});eo=e},em=()=>{eo?.close(),eo=null,ea=!1},ef=e=>{en!==e&&(en=e,er=null,eu(),en||g.focus())},ev=async()=>{if(en)return;let e=g.value.trim();if(e&&!t.getState().prompting){er=null;try{if(et){let r=I.value.trim();if(!r)return I.focus();await t.createPage(r,e),es=null,el=null,er={text:n.created,error:!1}}else{let{summary:r}=await t.prompt(e);er={text:r,error:!1}}g.value="",eh()}catch(e){er=ep(e)}eu(),g.focus()}},ey=()=>(el??(el=t.pages().then(e=>{es=e,ed=null,ew(),eu()},e=>{el=null,ed=ep(e).text,ew()})),el),ex=()=>{let e=B.value.trim().toLowerCase();return(es??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},ew=()=>{let r=ex();ec=Math.max(0,Math.min(ec,r.length-1)),V.textContent="",r.forEach((r,o)=>{let a=r.entryId===t.entryId,i=k(e,"li",{className:`option${o===ec?" active":""}`,id:`obelism-page-${o}`},k(e,"span",{className:"option-text"},k(e,"span",{textContent:r.name}),k(e,"span",{className:"option-path",textContent:r.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(o===ec)),"published"!==r.status&&i.appendChild(k(e,"span",{className:"badge",textContent:"draft"===r.status?n.pageDraft:n.pageChanged})),a){i.setAttribute("aria-current","page");let t=E(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",n.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>eE(r)),V.appendChild(i)});let o=V.children[ec];o?(B.setAttribute("aria-activedescendant",o.id),o.scrollIntoView?.({block:"nearest"})):B.removeAttribute("aria-activedescendant"),Y.textContent=(ed??(es?"":n.pagesLoading))||(0===r.length?n.pagesEmpty:""),Y.hidden=!Y.textContent,Y.className=`empty${ed?" error":""}`},ek=e=>{er=null,(ei=e)&&(B.value="",ec=Math.max(0,(es??[]).findIndex(({entryId:e})=>e===t.entryId)),ey(),ew()),eu(),(ei?B:q).focus()},eE=e=>{if(e.entryId===t.entryId)return ek(!1);t.openPage(e)},eC=e=>{(Q=e)||(ei=!1,ee=!1),eu(),i&&t.setSelecting(Q&&!et),Q&&i&&ey()},eA=e=>{et=e,er=null,t.setSelecting(Q&&!et),et&&t.select(null),eu(),(et?I:g).focus()},eS=async e=>{er=null;try{await t[e](),er={text:"save"===e?n.saved:n.published,error:!1}}catch(e){er=ep(e)}eu()};l.addEventListener("click",()=>{eC(!0),en||(et?I:g).focus()}),M.addEventListener("click",()=>eC(!1)),z.addEventListener("click",()=>{ee=!ee,eu(),ee||(en?z:g).focus()}),J.addEventListener("click",()=>void eS("save")),X.addEventListener("click",()=>void eS("publish")),_.addEventListener("click",()=>t.signOut()),c.addEventListener("click",()=>t.signOut()),f.addEventListener("click",()=>t.select(null)),N.addEventListener("click",()=>eA(!0)),U.addEventListener("click",()=>eA(!1)),A.addEventListener("click",()=>ef(!1)),S.addEventListener("click",()=>ef(!0)),q.addEventListener("click",()=>ek(!ei)),I.addEventListener("input",eu),I.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing?"Escape"===e.key&&eC(!1):(e.preventDefault(),g.focus())}),B.addEventListener("input",()=>{ec=0,ew()}),B.addEventListener("keydown",e=>{let t=V.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;ec=(ec+("ArrowDown"===e.key?1:-1)+t)%t,ew()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),ek(!1));else{e.preventDefault();let t=ex()[ec];t&&eE(t)}}),x.addEventListener("click",()=>{er=null,t.undo()}),K.addEventListener("submit",e=>{e.preventDefault(),ev()}),g.addEventListener("input",()=>{eh(),eu()}),g.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing?"Escape"===e.key&&eC(!1):(e.preventDefault(),ev())});let eL=t.on("change",eg);return eu(),e.body.appendChild(o),()=>{eL(),em(),o.remove()}},A="https://content.obelism.studio",S=(e,t)=>JSON.stringify(e)===JSON.stringify(t),L=Symbol.for("@obelism/content/bridge"),N=v({isEditing:!1,entryId:null,on:()=>{}},new URLSearchParams),U=({url:e,prompt:d=!0,pagePath:u}={})=>{let h;if("u"<typeof window)return N;let y=window;if(y[L])return y[L];if(y.ObelismBridge)h=v(y.ObelismBridge,new URLSearchParams(y.location.search));else{let v=(h=((e,r)=>{let d=new URLSearchParams(e.location.search),u=e.parent!==e&&d.has("cms_preview"),h=g(),v=[],y={...p,selecting:!0},x=e=>{y={...y,...e},h.emit("change",y)},w={isEditing:u,mode:u?"editor":null,entryId:d.get("cms_entry"),environment:d.get(n),on:h.on,getState:()=>y,...b,destroy:()=>{v.splice(0).forEach(e=>e())}};if(!u)return w;let k=e.document,E=(t,n={})=>{e.parent.postMessage({source:l,type:t,...n},r)},C=k.createElement("style");C.textContent=c(),k.head.appendChild(C),v.push(()=>C.remove());let A=(e,t)=>{if(k.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),y.selectedUid!==(e??null)&&x({selectedUid:e??null}),!e)return;let r=k.querySelector(f(e));r&&(r.setAttribute("data-cms-selected",""),t&&r.scrollIntoView({behavior:"smooth",block:"center"}))},S=e=>{let r=e.target,n=r?.closest?.(`[${t}]`);if(!n)return;e.preventDefault(),e.stopPropagation();let o=n.getAttribute(t);A(o,!1),E("select",{uid:o})};k.addEventListener("click",S,!0),v.push(()=>k.removeEventListener("click",S,!0));let L=()=>E("ready",{url:e.location.href}),N=new Map,U=0,P=e=>{let t=N.get(e);return t?(clearTimeout(t.timer),N.delete(e),0===N.size&&x({prompting:!1}),t):null};w.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!y.features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let n=`prompt_${++U}`,o=void 0===t.uid?y.selectedUid:t.uid;return new Promise((e,t)=>{let a=setTimeout(()=>{P(n)?.reject(Error("The editor did not answer in time"))},12e4);N.set(n,{resolve:e,reject:t,timer:a}),x({prompting:!0}),E("prompt",{id:n,prompt:r,uid:o})})},w.undo=()=>E("undo"),w.select=e=>{A(e,!1),E("select",{uid:e})};let I=null;v.push(()=>I?.destroy()),v.push(()=>{for(let e of N.keys())P(e)?.reject(Error("The bridge was destroyed"))});let $=t=>{if(t.origin!==r||t.source!==e.parent)return;let n=t.data;if(n&&"obelism-content-editor"===n.source){if("connect"===n.type)L();else if("update"===n.type&&n.entry)h.emit("update",{entry:n.entry,selectedUid:n.selectedUid??null}),e.requestAnimationFrame(()=>A(n.selectedUid,!1)),I?.refresh();else if("select"===n.type)A(n.uid,!0);else if("saved"===n.type||"published"===n.type)h.emit(n.type,{}),0===h.listeners.update.size&&e.location.reload();else if("features"===n.type&&Array.isArray(n.features))x({features:n.features.filter(e=>"string"==typeof e)});else if("stats"===n.type)x({stats:(e=>{if(!e||"object"!=typeof e||Array.isArray(e))return{};let t={};for(let[r,n]of Object.entries(e)){let{clicks:e,clickers:o,viewers:a,rate:i}=n??{};m(e)&&m(o)&&m(a)&&m(i)&&(t[r]={clicks:e,clickers:o,viewers:a,rate:i})}return t})(n.stats),statsVisible:!1!==n.visible}),(I||Object.keys(y.stats).length)&&(I??(I=((e,{selector:t,onSelect:r,labels:n})=>{let l=e.document,d={...o,...n},c=l.createElement("div");c.setAttribute("data-obelism-stats","");let p=c.attachShadow({mode:"open"}),g=l.createElement("style");g.textContent=i;let u=l.createElement("div");u.className="layer",p.append(g,u),l.body.appendChild(c);let h={},b=!1,m=null,f=()=>{if(m=null,u.replaceChildren(),u.hidden=!b,!b)return;let n=e.innerHeight;for(let[o,i]of Object.entries(h)){let c=l.querySelector(t(o));if(!c)continue;let p=c.getBoundingClientRect();if(!p.width&&!p.height||p.bottom<0||p.top>n)continue;let g=l.createElement("button");g.type="button",g.className="badge",g.dataset.uid=o,g.textContent=a(d.clicked,{rate:Math.round(100*i.rate)}),g.title=a(d.title,{clickers:i.clickers,viewers:i.viewers,clicks:i.clicks});let{place:h,top:b,left:m}=s(p,e.innerWidth);g.dataset.place=h,g.style.top=`${b}px`,g.style.left=`${m}px`,g.addEventListener("click",()=>r(o)),u.appendChild(g)}},v=()=>{null===m&&b&&(m=e.requestAnimationFrame(f))};e.addEventListener("scroll",v,{capture:!0,passive:!0}),e.addEventListener("resize",v);let y=e.MutationObserver,x="function"==typeof y?new y(v):null;return x?.observe(l.body,{childList:!0,subtree:!0}),{update(t,r){h=t,b=r,null!==m&&(e.cancelAnimationFrame?.(m),m=null),f()},refresh:v,destroy(){null!==m&&e.cancelAnimationFrame?.(m),e.removeEventListener("scroll",v,{capture:!0}),e.removeEventListener("resize",v),x?.disconnect(),c.remove()}}})(e,{selector:f,onSelect:e=>w.select(e)})),I.update(y.stats,y.statsVisible));else if("promptState"===n.type)x({canUndo:!0===n.canUndo});else if("promptResult"===n.type&&"string"==typeof n.id){let e=P(n.id);if(!e)return;!0===n.ok?e.resolve({summary:"string"==typeof n.summary?n.summary:""}):e.reject(Error("string"==typeof n.error?n.error:"The prompt failed"))}}};return e.addEventListener("message",$),v.push(()=>e.removeEventListener("message",$)),"loading"===k.readyState?(k.addEventListener("DOMContentLoaded",L,{once:!0}),v.push(()=>k.removeEventListener("DOMContentLoaded",L))):L(),w})(y,new URL(e||A).origin)).isEditing||y.parent!==y?null:(e=>{for(let t of e.cookie.split(";")){let[e,...r]=t.trim().split("=");if("obelism_content_editing"===e)try{let e=decodeURIComponent(r.join("="));return e.startsWith("/")&&!e.startsWith("//")?e:null}catch{break}}return null})(y.document);if(v&&(h=((e,n,{pagePath:o=e=>`/${e}`}={})=>{let a=e.document,i=g(),s=[],d=new Map,u=[],h=new Set,b=null,m=null,v=-1/0,y=new Map,x=p,w=e=>{x={...x,...e},i.emit("change",x)},k=()=>w({unsaved:[...d.values()].some(({content:e,saved:t})=>!S(e,t)),canUndo:u.length>0}),E=async(t,r)=>{let o=await e.fetch(`${n}/api/${t}`,void 0===r?{credentials:"same-origin"}:{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-obelism-content":"1"},body:JSON.stringify(r)}),a=await o.json().catch(()=>({}));if(401===o.status)throw w({features:[]}),Error("You were signed out. Sign in again to edit.");if(!o.ok)throw Error("string"==typeof a.error?a.error:`Obelism Content answered ${o.status}`);return a},C=()=>a.querySelector(`[${r}]`)?.getAttribute(r)??null,A=e=>{let t=e?a.querySelector(f(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??C()},L=()=>{if(!b)return;let e=b.space.locales.map(({code:e})=>e),t=a.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:b.space.defaultLocale},N=new Map,U=async e=>{let t=d.get(e);if(t)return t;let r=N.get(e);return r||(r=E(`entries/${encodeURIComponent(e)}`).then(t=>{let r=d.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return d.set(e,r),r}).finally(()=>N.delete(e)),N.set(e,r)),r},P=e=>{let t=void 0===e?x.selectedUid:e,r=A(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},I=e=>{a.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),x.selectedUid!==e&&w({selectedUid:e}),e&&a.querySelector(f(e))?.setAttribute("data-cms-selected","")},$=async t=>{if(0===i.listeners.update.size)return;let r=d.get(t)?.content,{entry:n}=await E(`entries/${encodeURIComponent(t)}/preview`,{content:r,locale:L()});i.emit("update",{entry:n,selectedUid:x.selectedUid}),e.requestAnimationFrame(()=>I(x.selectedUid))},M=e=>console.error("[@obelism/content bridge]",e),O=t=>{i.emit(t,{}),0===i.listeners.update.size&&e.location.reload()},T=async()=>{for(let[e,t]of d){if(S(t.content,t.saved))continue;let{draftRevision:r}=await E(`entries/${encodeURIComponent(e)}/save`,{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,h.add(e)}u.length=0,v=-1/0,k()},z={isEditing:!0,mode:"site",get entryId(){return C()},environment:null,on:i.on,getState:()=>x,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!x.features.includes("prompt"))throw Error("You may not edit content here");let{uid:n,entryId:o}=P(t.uid);w({prompting:!0});try{let e=await U(o),t=await E(`entries/${encodeURIComponent(o)}/prompt`,{prompt:r,content:e.content,locale:L(),uid:n});return u.push({entryId:o,content:e.content}),v=-1/0,e.content=t.content,k(),await $(o),{summary:t.summary}}finally{w({prompting:!1})}},async createPage(t,r){let n=r.trim();if(!n)throw Error("Say what the page is for");if(!t.trim())throw Error("Say where the page goes, like /pricing");if(!x.features.includes("create"))throw Error("You may not add pages here");if(x.unsaved)throw Error("Save or undo your changes before adding a page");w({prompting:!0});try{let r=await E("entries",{path:t,prompt:n,locale:L(),from:C()}),a=o(r.path,L()??"");return e.location.assign(a),{summary:r.summary,entryId:r.entryId,path:r.path,url:a}}finally{w({prompting:!1})}},async view(e={}){let{uid:t,entryId:r}=P(e.uid),n=await U(r),{view:o}=await E(`entries/${encodeURIComponent(r)}/view`,{content:n.content,locale:L(),uid:t});return o},async applyJson(e,t={}){if(!x.features.includes("prompt"))throw Error("You may not edit content here");if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Send the fields to change as an object");let{uid:r,entryId:n}=P(t.uid);w({prompting:!0});try{let t=await U(n),o=await E(`entries/${encodeURIComponent(n)}/apply`,{changes:e,content:t.content,locale:L(),uid:r});return S(o.content,t.content)||(u.push({entryId:n,content:t.content}),v=-1/0,t.content=o.content,k(),await $(n)),{changed:o.changed??[],...o.view&&{view:o.view}}}finally{w({prompting:!1})}},openForm(t,r={}){let{title:n="Content form",onReady:o,onError:a}=r;m?.();let s=!1,c=null,p=null,g=()=>{},h=e=>{s||a?.(e instanceof Error?e.message:String(e))},b=()=>{s||(s=!0,g(),c?.destroy(),m===b&&(m=null))};m=b;let f=()=>{if(s||!c)return;let e=A(x.selectedUid);if(!e)return;let t=d.get(e);if(!t)return void U(e).then(f,h);let r={entryId:e,content:t.content,locale:L(),selectedUid:x.selectedUid};p&&p.entryId===r.entryId&&p.content===r.content&&p.locale===r.locale&&p.selectedUid===r.selectedUid||(p=r,c.show(r))},w=(e,t)=>{let r=t??p?.entryId,n=void 0===r?void 0:d.get(r);if(s||void 0===r||!n||S(e,n.content))return;let o=Date.now();o-v>=1e3&&u.push({entryId:r,content:n.content}),v=o,n.content=e,p?.entryId===r&&(p={...p,content:e}),k(),clearTimeout(y.get(r)),y.set(r,setTimeout(()=>{y.delete(r),$(r).catch(M)},300))};return(async()=>{if(!x.features.includes("form"))throw Error("You may not edit content here");await U(P(void 0).entryId);let{url:r}=await E("form",{});s||(c=((e,t,r,n,o)=>{let a=null;try{a=new URL(r)}catch{}if(!a||!/^https?:$/.test(a.protocol))throw Error("Obelism Content sent no form to open");let i=a.origin,s=t.ownerDocument.createElement("iframe");s.title=n,s.src=r;let d=!1,c=null,p=()=>{d&&c&&s.contentWindow?.postMessage({source:l,type:"content",...c},i)},g=setTimeout(()=>{d||o.onError("The form did not open")},3e4),u=e=>{if(e.origin!==i||!s.contentWindow||e.source!==s.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)d=!0,clearTimeout(g),o.onReady(),p();else{let e;if("change"!==t.type||!(e=t.content)||"object"!=typeof e||Array.isArray(e))if("height"===t.type){let e=t.height;if("number"==typeof e&&Number.isFinite(e)){let t=Math.round(Math.min(Math.max(e,80),4e3));s.style.height=`min(${t}px, 60vh)`}}else"error"===t.type&&o.onError("string"==typeof t.message&&t.message?t.message:"The form failed");else o.onChange(t.content,"string"==typeof t.entryId?t.entryId:void 0)}};return e.addEventListener("message",u),t.appendChild(s),{show(e){c=e,p()},destroy(){clearTimeout(g),e.removeEventListener("message",u),s.remove()}}})(e,t,"string"==typeof r?r:"",n,{onReady:()=>o?.(),onChange:w,onError:e=>a?.(e)}),g=i.on("change",f),f())})().catch(h),{close:b}},async pages(){let{pages:e}=await E("pages"),t=[L(),b?.space.defaultLocale];return e.flatMap(e=>{let r=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],n=void 0===r?void 0:e.paths[r];return void 0===r||void 0===n?[]:[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:n,url:o(n,r)}]})},openPage(t){(!x.unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(d.clear(),u.length=0,k(),e.location.assign(t.url))},undo(){let e=u.pop(),t=e&&d.get(e.entryId);e&&t&&(v=-1/0,t.content=e.content,k(),$(e.entryId).catch(M))},async save(){if(!x.features.includes("save"))throw Error("You may not edit content here");w({saving:!0});try{await T()}finally{w({saving:!1})}O("saved")},async publish(){if(!x.features.includes("publish"))throw Error("You may not publish here");w({publishing:!0});try{await T();let e=C(),t=h.size>0?[...h]:e?[e]:[];if(0===t.length)throw Error("Nothing on this page is marked as an entry: add editable(entry)");for(let e of t)await E(`entries/${encodeURIComponent(e)}/publish`,{}),h.delete(e)}finally{w({publishing:!1})}O("published")},signOut(){if(x.unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;d.clear(),k();let t=e.location.pathname+e.location.search;e.location.href=`${n}/logout?return_to=${encodeURIComponent(t)}`},select(e){I(e)},setSelecting(e){e?a.documentElement.setAttribute("data-cms-selecting",""):a.documentElement.removeAttribute("data-cms-selecting"),w({selecting:e})},destroy(){m?.(),y.forEach(e=>clearTimeout(e)),y.clear(),s.splice(0).forEach(e=>e())}},j=a.createElement("style");j.textContent=c("html[data-cms-selecting] "),a.head.appendChild(j),s.push(()=>j.remove()),s.push(()=>a.documentElement.removeAttribute("data-cms-selecting"));let R=e=>{if(!x.selecting)return;let r=e.target,n=r?.closest?.(`[${t}]`);n&&(e.preventDefault(),e.stopPropagation(),I(n.getAttribute(t)))};a.addEventListener("click",R,!0),s.push(()=>a.removeEventListener("click",R,!0));let D=e=>{x.unsaved&&(e.preventDefault(),e.returnValue="")};return e.addEventListener("beforeunload",D),s.push(()=>e.removeEventListener("beforeunload",D)),E("session").then(e=>{b=e,w({features:e.features})}).catch(e=>console.error("[@obelism/content bridge]",e)),z})(y,v,{pagePath:u})),h.isEditing&&d){let e=C(y.document,h,!0===d?{}:d),t=h.destroy;h.destroy=()=>{e(),t()}}}return y[L]=h,h};(e=window).ObelismBridge=U((e=>{let t=e?.dataset.url,r=t||A;if(!t&&e?.src){let t=new URL(e.src);"/bridge.js"===t.pathname&&(r=t.origin)}return{url:r,prompt:e?.dataset.prompt!=="false"}})(document.currentScript)),e.ObelismContent={getContentBridge:U,mountPromptBox:C}}();
|
|
236
|
+
`,E=(e,t,r={},...o)=>{let n=e.createElement(t);for(let t of(Object.assign(n,r),o))n.appendChild("string"==typeof t?e.createTextNode(t):t);return n},C=(e,t)=>{let r=E(e,"span",{className:"icon"});return r.setAttribute("aria-hidden","true"),r.innerHTML=`<svg viewBox="0 0 24 24">${w[t]}</svg>`,r},P=(e,t,r={})=>{let o={...x,...r.labels},n=E(e,"div");n.setAttribute("data-obelism-content-prompt","");let a=n.attachShadow({mode:"open"}),i="site"===t.mode,s=E(e,"span",{textContent:o.open}),l=E(e,"button",{className:"pill",type:"button"},s,E(e,"span",{className:"mark",textContent:"⁜"})),d=E(e,"span",{className:"pill compact"},`${o.viewingDrafts} \xb7 `),c=E(e,"button",{className:"link",type:"button",textContent:o.signOut});d.appendChild(c);let p=E(e,"p",{className:"status"});p.setAttribute("role","status");let g=E(e,"textarea",{placeholder:o.placeholder,rows:1});g.setAttribute("aria-label",o.open);let u=E(e,"div",{className:"form"}),h=C(e,"page"),b=C(e,"block"),m=E(e,"span"),f=E(e,"button",{type:"button",title:o.clearBlock});f.setAttribute("aria-label",o.clearBlock),f.appendChild(C(e,"close"));let v=E(e,"span",{className:"chip scope"},h,b,m,f),y=E(e,"button",{className:"action chip",type:"button"},C(e,"undo"),o.undo),w=t=>{let r=E(e,"button",{type:"button",textContent:t});return r.setAttribute("aria-pressed","false"),r},P=w(o.modePrompt),A=w(o.form),S=E(e,"span",{className:"modes"},P,A);S.setAttribute("role","group"),S.setAttribute("aria-label",o.modes);let L=E(e,"button",{className:"action chip",type:"button"},C(e,"newPage"),o.newPage),N=E(e,"button",{className:"action chip product",type:"button"},C(e,"newPage"),o.addProductPage),U=E(e,"button",{type:"button",title:o.newPageCancel});U.setAttribute("aria-label",o.newPageCancel),U.appendChild(C(e,"close"));let I=E(e,"span",{className:"chip scope"},C(e,"newPage"),E(e,"span",{textContent:o.newPage}),U),$=E(e,"input",{type:"text",placeholder:o.pathPlaceholder,autocomplete:"off",spellcheck:!1}),M=E(e,"label",{className:"path"},E(e,"span",{textContent:o.path}),$),O=E(e,"button",{className:"close icon-button",type:"button",title:o.close},C(e,"close"));O.setAttribute("aria-label",o.close);let T=C(e,"minimize"),j=C(e,"expand"),z=E(e,"button",{className:"icon-button",type:"button"},T,j),R=E(e,"button",{className:"action primary icon-button",type:"submit"},E(e,"span",{className:"visually-hidden",textContent:o.send}),C(e,"send"));R.title=o.send;let D=E(e,"span",{className:"divider"}),F=E(e,"div",{className:"toolbar"},v,I,S,y,N,L,E(e,"span",{className:"spacer"}),z,O,D,R),q=E(e,"span",{textContent:o.pages}),B=E(e,"button",{className:"chip page-chip",type:"button",title:o.pages},C(e,"page"),q,C(e,"chevrons"));B.setAttribute("aria-haspopup","listbox"),B.setAttribute("aria-expanded","false"),B.setAttribute("aria-controls","obelism-pages");let H=E(e,"input",{type:"text",placeholder:o.pagesSearch,autocomplete:"off",spellcheck:!1});H.setAttribute("role","combobox"),H.setAttribute("aria-label",o.pagesSearch),H.setAttribute("aria-autocomplete","list"),H.setAttribute("aria-expanded","true"),H.setAttribute("aria-controls","obelism-pages");let V=E(e,"ul",{className:"options",id:"obelism-pages"});V.setAttribute("role","listbox"),V.setAttribute("aria-label",o.pages);let Y=E(e,"p",{className:"empty"}),W=E(e,"div",{className:"pages"},E(e,"label",{className:"search"},C(e,"search"),H),V,Y),_=E(e,"span",{className:"unsaved"});_.appendChild(E(e,"span",{className:"dot"})),_.appendChild(e.createTextNode(o.unsaved));let J=E(e,"button",{className:"link",type:"button",textContent:o.signOut}),X=E(e,"button",{className:"action chip",type:"button",textContent:o.save}),Z=E(e,"button",{className:"action chip",type:"button",textContent:o.publish}),K=E(e,"div",{className:"footer"},B,_,E(e,"span",{className:"spacer"}),J,X,Z),G=E(e,"form",{className:"panel"},p,M,g,u,F,W,K),Q=E(e,"div",{className:"root"},E(e,"div",{className:"bar"},l,d),G);a.append(E(e,"style",{textContent:k}),Q);let ee=!1,et=!1,er=!1,eo=null,en=!1,ea=null,ei=!1,es=!1,el=null,ed=null,ec=null,ep=0,eg=e=>({text:e instanceof Error?e.message:String(e),error:!0}),eu=e=>{let r=e.features.includes("prompt"),n=e.saving||e.publishing,a=e.prompting||n;Q.hidden=!r&&!i,l.hidden=ee||!r,d.hidden=r||!i,G.hidden=!ee||!r;let c=i&&e.features.includes("create"),x=i&&null===t.entryId,w=x&&c&&null!==t.product,k=x&&c&&!w;c||(er=!1),k&&(er=!0),(er||x||!i)&&(en=!1);let E=ee&&r&&en;E&&!ea?em():!E&&ea&&ef();let C=w&&!er;s.textContent=C?o.addProductPage:k?o.newPage:o.open,U.hidden=k,v.hidden=er||C,I.hidden=!er,N.hidden=!C,N.disabled=a,L.hidden=er||en||!c,L.disabled=a,et&&(es=!1),M.hidden=!er||es||et,$.disabled=a,g.hidden=en||es||et||C,u.hidden=!en||es||et,u.classList.toggle("loading",ei),F.hidden=es,W.hidden=!es,g.placeholder=er?o.newPagePlaceholder:o.placeholder,m.textContent=e.selectedUid?o.scopeBlock:o.scopeEntry,f.hidden=!e.selectedUid,h.hidden=!!e.selectedUid,b.hidden=!e.selectedUid,S.hidden=!i||er||x||!e.features.includes("form"),P.setAttribute("aria-pressed",String(!en)),A.setAttribute("aria-pressed",String(en)),S.querySelectorAll("button").forEach(e=>{e.disabled=a}),y.hidden=er||!e.canUndo,y.disabled=a,R.hidden=en||et||C,D.hidden=en||et||C;let O=et?o.expand:o.minimize;z.title=O,z.setAttribute("aria-label",O),z.setAttribute("aria-expanded",String(!et)),T.hidden=et,j.hidden=!et,R.disabled=a||""===g.value.trim()||er&&""===$.value.trim(),g.disabled=a,X.hidden=!e.features.includes("save")||x,X.disabled=a||!e.unsaved,X.textContent=e.saving?o.saving:o.save,Z.hidden=!e.features.includes("publish")||x,Z.disabled=a,Z.textContent=e.publishing?o.publishing:o.publish,J.hidden=!i,K.hidden=!i,_.hidden=!e.unsaved,B.hidden=!i,B.setAttribute("aria-expanded",String(es)),q.textContent=el?.find(({entryId:e})=>e===t.entryId)?.name??o.pages;let H=en&&ei&&!es,V=e.prompting||H,Y=e.prompting?er?o.creating:C?o.addingProductPage:o.working:H?o.formLoading:eo?.text??(C?o.productPageHint:!i||er||es||e.selectedUid?"":o.selectHint);p.textContent=Y,p.hidden=!Y||et,p.className=`status${V?" working":""}${!a&&!H&&eo?.error?" error":""}`},eh=()=>eu(t.getState()),eb=()=>{g.style.height="auto",g.style.height=`${g.scrollHeight}px`},em=()=>{ei=!0,u.classList.add("loading");let e=t.openForm(u,{title:o.formTitle,onReady:()=>{ea===e&&(ei=!1,eo=null,eh())},onError:t=>{ea===e&&(ei=!1,eo={text:t,error:!0},eh())}});ea=e},ef=()=>{ea?.close(),ea=null,ei=!1},ev=e=>{en!==e&&(en=e,eo=null,eh(),en||g.focus())},ey=async()=>{if(en)return;let e=g.value.trim();if(e&&!t.getState().prompting){eo=null;try{if(er){let r=$.value.trim();if(!r)return $.focus();await t.createPage(r,e),el=null,ed=null,eo={text:o.created,error:!1}}else{let{summary:r}=await t.prompt(e);eo={text:r,error:!1}}g.value="",eb()}catch(e){eo=eg(e)}eh(),g.focus()}},ex=()=>(ed??(ed=t.pages().then(e=>{el=e,ec=null,ek(),eh()},e=>{ed=null,ec=eg(e).text,ek()})),ed),ew=()=>{let e=H.value.trim().toLowerCase();return(el??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},ek=()=>{let r=ew();ep=Math.max(0,Math.min(ep,r.length-1)),V.textContent="",r.forEach((r,n)=>{let a=r.entryId===t.entryId,i=E(e,"li",{className:`option${n===ep?" active":""}`,id:`obelism-page-${n}`},E(e,"span",{className:"option-text"},E(e,"span",{textContent:r.name}),E(e,"span",{className:"option-path",textContent:r.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(n===ep)),"published"!==r.status&&i.appendChild(E(e,"span",{className:"badge",textContent:"draft"===r.status?o.pageDraft:o.pageChanged})),a){i.setAttribute("aria-current","page");let t=C(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",o.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>eC(r)),V.appendChild(i)});let n=V.children[ep];n?(H.setAttribute("aria-activedescendant",n.id),n.scrollIntoView?.({block:"nearest"})):H.removeAttribute("aria-activedescendant"),Y.textContent=(ec??(el?"":o.pagesLoading))||(0===r.length?o.pagesEmpty:""),Y.hidden=!Y.textContent,Y.className=`empty${ec?" error":""}`},eE=e=>{eo=null,(es=e)&&(H.value="",ep=Math.max(0,(el??[]).findIndex(({entryId:e})=>e===t.entryId)),ex(),ek()),eh(),(es?H:B).focus()},eC=e=>{if(e.entryId===t.entryId)return eE(!1);t.openPage(e)},eP=e=>{(ee=e)||(es=!1,et=!1),eh(),i&&t.setSelecting(ee&&!er),ee&&i&&ex()},eA=e=>{er=e,eo=null,t.setSelecting(ee&&!er),er&&t.select(null),eh(),(er?$:g).focus()},eS=async e=>{eo=null;try{await t[e](),eo={text:"save"===e?o.saved:o.published,error:!1}}catch(e){eo=eg(e)}eh()};l.addEventListener("click",()=>{eP(!0),en||(er?$:g).focus()}),O.addEventListener("click",()=>eP(!1)),z.addEventListener("click",()=>{et=!et,eh(),et||(en?z:g).focus()}),X.addEventListener("click",()=>void eS("save")),Z.addEventListener("click",()=>void eS("publish")),J.addEventListener("click",()=>t.signOut()),c.addEventListener("click",()=>t.signOut()),f.addEventListener("click",()=>t.select(null)),L.addEventListener("click",()=>eA(!0)),N.addEventListener("click",async()=>{eo=null;try{await t.createProductPage(),eo={text:o.addedProductPage,error:!1}}catch(e){eo=eg(e)}eh()}),U.addEventListener("click",()=>eA(!1)),P.addEventListener("click",()=>ev(!1)),A.addEventListener("click",()=>ev(!0)),B.addEventListener("click",()=>eE(!es)),$.addEventListener("input",eh),$.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing?"Escape"===e.key&&eP(!1):(e.preventDefault(),g.focus())}),H.addEventListener("input",()=>{ep=0,ek()}),H.addEventListener("keydown",e=>{let t=V.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;ep=(ep+("ArrowDown"===e.key?1:-1)+t)%t,ek()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),eE(!1));else{e.preventDefault();let t=ew()[ep];t&&eC(t)}}),y.addEventListener("click",()=>{eo=null,t.undo()}),G.addEventListener("submit",e=>{e.preventDefault(),ey()}),g.addEventListener("input",()=>{eb(),eh()}),g.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing?"Escape"===e.key&&eP(!1):(e.preventDefault(),ey())});let eL=t.on("change",eu);return eh(),e.body.appendChild(n),()=>{eL(),ef(),n.remove()}},A="https://content.obelism.studio",S=(e,t)=>JSON.stringify(e)===JSON.stringify(t),L=Symbol.for("@obelism/content/bridge"),N=y({isEditing:!1,entryId:null,on:()=>{}},new URLSearchParams),U=({url:e,prompt:c=!0,pagePath:h,productPath:b}={})=>{let x;if("u"<typeof window)return N;let w=window;if(w[L])return w[L];if(w.ObelismBridge)x=y(w.ObelismBridge,new URLSearchParams(w.location.search));else{let y=(x=((e,r)=>{let o=new URLSearchParams(e.location.search),c=e.parent!==e&&o.has("cms_preview"),h=u(),b=[],y={...g,selecting:!0},x=e=>{y={...y,...e},h.emit("change",y)},w={isEditing:c,mode:c?"editor":null,entryId:o.get("cms_entry"),environment:o.get(n),product:null,on:h.on,getState:()=>y,...m,destroy:()=>{b.splice(0).forEach(e=>e())}};if(!c)return w;let k=e.document,E=(t,o={})=>{e.parent.postMessage({source:d,type:t,...o},r)},C=k.createElement("style");C.textContent=p(),k.head.appendChild(C),b.push(()=>C.remove());let P=(e,t)=>{if(k.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),y.selectedUid!==(e??null)&&x({selectedUid:e??null}),!e)return;let r=k.querySelector(v(e));r&&(r.setAttribute("data-cms-selected",""),t&&r.scrollIntoView({behavior:"smooth",block:"center"}))},A=e=>{let r=e.target,o=r?.closest?.(`[${t}]`);if(!o)return;e.preventDefault(),e.stopPropagation();let n=o.getAttribute(t);P(n,!1),E("select",{uid:n})};k.addEventListener("click",A,!0),b.push(()=>k.removeEventListener("click",A,!0));let S=()=>E("ready",{url:e.location.href}),L=new Map,N=0,U=e=>{let t=L.get(e);return t?(clearTimeout(t.timer),L.delete(e),0===L.size&&x({prompting:!1}),t):null};w.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!y.features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let o=`prompt_${++N}`,n=void 0===t.uid?y.selectedUid:t.uid;return new Promise((e,t)=>{let a=setTimeout(()=>{U(o)?.reject(Error("The editor did not answer in time"))},12e4);L.set(o,{resolve:e,reject:t,timer:a}),x({prompting:!0}),E("prompt",{id:o,prompt:r,uid:n})})},w.undo=()=>E("undo"),w.select=e=>{P(e,!1),E("select",{uid:e})};let I=null;b.push(()=>I?.destroy()),b.push(()=>{for(let e of L.keys())U(e)?.reject(Error("The bridge was destroyed"))});let $=t=>{if(t.origin!==r||t.source!==e.parent)return;let o=t.data;if(o&&"obelism-content-editor"===o.source){if("connect"===o.type)S();else if("update"===o.type&&o.entry)h.emit("update",{entry:o.entry,selectedUid:o.selectedUid??null}),e.requestAnimationFrame(()=>P(o.selectedUid,!1)),I?.refresh();else if("select"===o.type)P(o.uid,!0);else if("saved"===o.type||"published"===o.type)h.emit(o.type,{}),0===h.listeners.update.size&&e.location.reload();else if("features"===o.type&&Array.isArray(o.features))x({features:o.features.filter(e=>"string"==typeof e)});else if("stats"===o.type)x({stats:(e=>{if(!e||"object"!=typeof e||Array.isArray(e))return{};let t={};for(let[r,o]of Object.entries(e)){let{clicks:e,clickers:n,viewers:a,rate:i}=o??{};f(e)&&f(n)&&f(a)&&f(i)&&(t[r]={clicks:e,clickers:n,viewers:a,rate:i})}return t})(o.stats),statsVisible:!1!==o.visible}),(I||Object.keys(y.stats).length)&&(I??(I=((e,{selector:t,onSelect:r,labels:o})=>{let n=e.document,d={...a,...o},c=n.createElement("div");c.setAttribute("data-obelism-stats","");let p=c.attachShadow({mode:"open"}),g=n.createElement("style");g.textContent=s;let u=n.createElement("div");u.className="layer",p.append(g,u),n.body.appendChild(c);let h={},b=!1,m=null,f=()=>{if(m=null,u.replaceChildren(),u.hidden=!b,!b)return;let o=e.innerHeight;for(let[a,s]of Object.entries(h)){let c=n.querySelector(t(a));if(!c)continue;let p=c.getBoundingClientRect();if(!p.width&&!p.height||p.bottom<0||p.top>o)continue;let g=n.createElement("button");g.type="button",g.className="badge",g.dataset.uid=a,g.textContent=i(d.clicked,{rate:Math.round(100*s.rate)}),g.title=i(d.title,{clickers:s.clickers,viewers:s.viewers,clicks:s.clicks});let{place:h,top:b,left:m}=l(p,e.innerWidth);g.dataset.place=h,g.style.top=`${b}px`,g.style.left=`${m}px`,g.addEventListener("click",()=>r(a)),u.appendChild(g)}},v=()=>{null===m&&b&&(m=e.requestAnimationFrame(f))};e.addEventListener("scroll",v,{capture:!0,passive:!0}),e.addEventListener("resize",v);let y=e.MutationObserver,x="function"==typeof y?new y(v):null;return x?.observe(n.body,{childList:!0,subtree:!0}),{update(t,r){h=t,b=r,null!==m&&(e.cancelAnimationFrame?.(m),m=null),f()},refresh:v,destroy(){null!==m&&e.cancelAnimationFrame?.(m),e.removeEventListener("scroll",v,{capture:!0}),e.removeEventListener("resize",v),x?.disconnect(),c.remove()}}})(e,{selector:v,onSelect:e=>w.select(e)})),I.update(y.stats,y.statsVisible));else if("promptState"===o.type)x({canUndo:!0===o.canUndo});else if("promptResult"===o.type&&"string"==typeof o.id){let e=U(o.id);if(!e)return;!0===o.ok?e.resolve({summary:"string"==typeof o.summary?o.summary:""}):e.reject(Error("string"==typeof o.error?o.error:"The prompt failed"))}}};return e.addEventListener("message",$),b.push(()=>e.removeEventListener("message",$)),"loading"===k.readyState?(k.addEventListener("DOMContentLoaded",S,{once:!0}),b.push(()=>k.removeEventListener("DOMContentLoaded",S))):S(),w})(w,new URL(e||A).origin)).isEditing||w.parent!==w?null:(e=>{for(let t of e.cookie.split(";")){let[e,...r]=t.trim().split("=");if("obelism_content_editing"===e)try{let e=decodeURIComponent(r.join("="));return e.startsWith("/")&&!e.startsWith("//")?e:null}catch{break}}return null})(w.document);if(y&&(x=((e,n,{pagePath:a=e=>`/${e}`,productPath:i}={})=>{let s=e.document,l=u(),c=[],h=new Map,b=[],m=new Set,f=null,y=null,x=-1/0,w=new Map,k=g,E=e=>{k={...k,...e},l.emit("change",k)},C=()=>E({unsaved:[...h.values()].some(({content:e,saved:t})=>!S(e,t)),canUndo:b.length>0}),P=async(t,r)=>{let o=await e.fetch(`${n}/api/${t}`,void 0===r?{credentials:"same-origin"}:{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","x-obelism-content":"1"},body:JSON.stringify(r)}),a=await o.json().catch(()=>({}));if(401===o.status)throw E({features:[]}),Error("You were signed out. Sign in again to edit.");if(!o.ok)throw Error("string"==typeof a.error?a.error:`Obelism Content answered ${o.status}`);return a},A=()=>s.querySelector(`[${r}]`)?.getAttribute(r)??null,L=()=>{let e=s.querySelector(`[${o}]`),t=e?.getAttribute(o),r=e?.getAttribute("data-cms-product-handle");return t&&r?{id:t,handle:r}:null},N=e=>{let t=e?s.querySelector(v(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??A()},U=()=>{if(!f)return;let e=f.space.locales.map(({code:e})=>e),t=s.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:f.space.defaultLocale},I=new Map,$=async e=>{let t=h.get(e);if(t)return t;let r=I.get(e);return r||(r=P(`entries/${encodeURIComponent(e)}`).then(t=>{let r=h.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return h.set(e,r),r}).finally(()=>I.delete(e)),I.set(e,r)),r},M=e=>{let t=void 0===e?k.selectedUid:e,r=N(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},O=e=>{s.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),k.selectedUid!==e&&E({selectedUid:e}),e&&s.querySelector(v(e))?.setAttribute("data-cms-selected","")},T=async t=>{if(0===l.listeners.update.size)return;let r=h.get(t)?.content,{entry:o}=await P(`entries/${encodeURIComponent(t)}/preview`,{content:r,locale:U()});l.emit("update",{entry:o,selectedUid:k.selectedUid}),e.requestAnimationFrame(()=>O(k.selectedUid))},j=e=>console.error("[@obelism/content bridge]",e),z=t=>{l.emit(t,{}),0===l.listeners.update.size&&e.location.reload()},R=async()=>{for(let[e,t]of h){if(S(t.content,t.saved))continue;let{draftRevision:r}=await P(`entries/${encodeURIComponent(e)}/save`,{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,m.add(e)}b.length=0,x=-1/0,C()},D={isEditing:!0,mode:"site",get entryId(){return A()},get product(){return L()},environment:null,on:l.on,getState:()=>k,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!k.features.includes("prompt"))throw Error("You may not edit content here");let{uid:o,entryId:n}=M(t.uid);E({prompting:!0});try{let e=await $(n),t=await P(`entries/${encodeURIComponent(n)}/prompt`,{prompt:r,content:e.content,locale:U(),uid:o});return b.push({entryId:n,content:e.content}),x=-1/0,e.content=t.content,C(),await T(n),{summary:t.summary}}finally{E({prompting:!1})}},async createPage(t,r){let o=r.trim();if(!o)throw Error("Say what the page is for");if(!t.trim())throw Error("Say where the page goes, like /pricing");if(!k.features.includes("create"))throw Error("You may not add pages here");if(k.unsaved)throw Error("Save or undo your changes before adding a page");E({prompting:!0});try{let r=await P("entries",{path:t,prompt:o,locale:U(),from:A()}),n=a(r.path,U()??"");return e.location.assign(n),{summary:r.summary,entryId:r.entryId,path:r.path,url:n}}finally{E({prompting:!1})}},async createProductPage(t=L()??void 0){if(!t)throw Error("Nothing on this page is marked as a product: add editableProduct(product)");if(!k.features.includes("create"))throw Error("You may not add pages here");if(k.unsaved)throw Error("Save or undo your changes before adding a page");E({prompting:!0});try{let r=await P("product-pages",{product:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{E({prompting:!1})}},async view(e={}){let{uid:t,entryId:r}=M(e.uid),o=await $(r),{view:n}=await P(`entries/${encodeURIComponent(r)}/view`,{content:o.content,locale:U(),uid:t});return n},async applyJson(e,t={}){if(!k.features.includes("prompt"))throw Error("You may not edit content here");if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Send the fields to change as an object");let{uid:r,entryId:o}=M(t.uid);E({prompting:!0});try{let t=await $(o),n=await P(`entries/${encodeURIComponent(o)}/apply`,{changes:e,content:t.content,locale:U(),uid:r});return S(n.content,t.content)||(b.push({entryId:o,content:t.content}),x=-1/0,t.content=n.content,C(),await T(o)),{changed:n.changed??[],...n.view&&{view:n.view}}}finally{E({prompting:!1})}},openForm(t,r={}){let{title:o="Content form",onReady:n,onError:a}=r;y?.();let i=!1,s=null,c=null,p=()=>{},g=e=>{i||a?.(e instanceof Error?e.message:String(e))},u=()=>{i||(i=!0,p(),s?.destroy(),y===u&&(y=null))};y=u;let m=()=>{if(i||!s)return;let e=N(k.selectedUid);if(!e)return;let t=h.get(e);if(!t)return void $(e).then(m,g);let r={entryId:e,content:t.content,locale:U(),selectedUid:k.selectedUid};c&&c.entryId===r.entryId&&c.content===r.content&&c.locale===r.locale&&c.selectedUid===r.selectedUid||(c=r,s.show(r))},f=(e,t)=>{let r=t??c?.entryId,o=void 0===r?void 0:h.get(r);if(i||void 0===r||!o||S(e,o.content))return;let n=Date.now();n-x>=1e3&&b.push({entryId:r,content:o.content}),x=n,o.content=e,c?.entryId===r&&(c={...c,content:e}),C(),clearTimeout(w.get(r)),w.set(r,setTimeout(()=>{w.delete(r),T(r).catch(j)},300))};return(async()=>{if(!k.features.includes("form"))throw Error("You may not edit content here");await $(M(void 0).entryId);let{url:r}=await P("form",{});i||(s=((e,t,r,o,n)=>{let a=null;try{a=new URL(r)}catch{}if(!a||!/^https?:$/.test(a.protocol))throw Error("Obelism Content sent no form to open");let i=a.origin,s=t.ownerDocument.createElement("iframe");s.title=o,s.src=r;let l=!1,c=null,p=()=>{l&&c&&s.contentWindow?.postMessage({source:d,type:"content",...c},i)},g=setTimeout(()=>{l||n.onError("The form did not open")},3e4),u=e=>{if(e.origin!==i||!s.contentWindow||e.source!==s.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)l=!0,clearTimeout(g),n.onReady(),p();else{let e;if("change"!==t.type||!(e=t.content)||"object"!=typeof e||Array.isArray(e))if("height"===t.type){let e=t.height;if("number"==typeof e&&Number.isFinite(e)){let t=Math.round(Math.min(Math.max(e,80),4e3));s.style.height=`min(${t}px, 60vh)`}}else"error"===t.type&&n.onError("string"==typeof t.message&&t.message?t.message:"The form failed");else n.onChange(t.content,"string"==typeof t.entryId?t.entryId:void 0)}};return e.addEventListener("message",u),t.appendChild(s),{show(e){c=e,p()},destroy(){clearTimeout(g),e.removeEventListener("message",u),s.remove()}}})(e,t,"string"==typeof r?r:"",o,{onReady:()=>n?.(),onChange:f,onError:e=>a?.(e)}),p=l.on("change",m),m())})().catch(g),{close:u}},async pages(){let{pages:e}=await P("pages"),t=[U(),f?.space.defaultLocale];return e.flatMap(e=>{let r,o=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],n=void 0===o?void 0:e.paths[o];return void 0===o||void 0===n?[]:[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:n,url:e.product?(r=e.product.handle,i?i(r,o):(f?.productPath??"/products/{handle}").replaceAll("{handle}",encodeURIComponent(r))):a(n,o),product:e.product??null}]})},openPage(t){(!k.unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(h.clear(),b.length=0,C(),e.location.assign(t.url))},undo(){let e=b.pop(),t=e&&h.get(e.entryId);e&&t&&(x=-1/0,t.content=e.content,C(),T(e.entryId).catch(j))},async save(){if(!k.features.includes("save"))throw Error("You may not edit content here");E({saving:!0});try{await R()}finally{E({saving:!1})}z("saved")},async publish(){if(!k.features.includes("publish"))throw Error("You may not publish here");E({publishing:!0});try{await R();let e=A(),t=m.size>0?[...m]:e?[e]:[];if(0===t.length)throw Error("Nothing on this page is marked as an entry: add editable(entry)");for(let e of t)await P(`entries/${encodeURIComponent(e)}/publish`,{}),m.delete(e)}finally{E({publishing:!1})}z("published")},signOut(){if(k.unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;h.clear(),C();let t=e.location.pathname+e.location.search;e.location.href=`${n}/logout?return_to=${encodeURIComponent(t)}`},select(e){O(e)},setSelecting(e){e?s.documentElement.setAttribute("data-cms-selecting",""):s.documentElement.removeAttribute("data-cms-selecting"),E({selecting:e})},destroy(){y?.(),w.forEach(e=>clearTimeout(e)),w.clear(),c.splice(0).forEach(e=>e())}},F=s.createElement("style");F.textContent=p("html[data-cms-selecting] "),s.head.appendChild(F),c.push(()=>F.remove()),c.push(()=>s.documentElement.removeAttribute("data-cms-selecting"));let q=e=>{if(!k.selecting)return;let r=e.target,o=r?.closest?.(`[${t}]`);o&&(e.preventDefault(),e.stopPropagation(),O(o.getAttribute(t)))};s.addEventListener("click",q,!0),c.push(()=>s.removeEventListener("click",q,!0));let B=e=>{k.unsaved&&(e.preventDefault(),e.returnValue="")};return e.addEventListener("beforeunload",B),c.push(()=>e.removeEventListener("beforeunload",B)),P("session").then(e=>{f=e,E({features:e.features})}).catch(e=>console.error("[@obelism/content bridge]",e)),D})(w,y,{pagePath:h,productPath:b})),x.isEditing&&c){let e=P(w.document,x,!0===c?{}:c),t=x.destroy;x.destroy=()=>{e(),t()}}}return w[L]=x,x};(e=window).ObelismBridge=U((e=>{let t=e?.dataset.url,r=t||A;if(!t&&e?.src){let t=new URL(e.src);"/bridge.js"===t.pathname&&(r=t.origin)}return{url:r,prompt:e?.dataset.prompt!=="false"}})(document.currentScript)),e.ObelismContent={getContentBridge:U,mountPromptBox:P}}();
|