@obelism/content 0.20.0 → 0.21.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 +10 -0
- package/dist/bridge.d.mts +3 -0
- package/dist/bridge.d.mts.map +1 -1
- package/dist/bridge.d.ts +3 -0
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.global.js +4 -4
- package/dist/bridge.js +22 -7
- package/dist/bridge.mjs +22 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -127,6 +127,16 @@ const bridge = getContentBridge({ prompt: false })
|
|
|
127
127
|
const unmount = mountPromptBox(document, bridge, { labels: { open: 'Ask' } })
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
`actions` puts controls of your own in the box: an element of your page,
|
|
131
|
+
shown next to the closed box and in the open box's footer (by a `<slot>`, so
|
|
132
|
+
your CSS styles it). `signOut: false` leaves Sign out out. Content's canvas
|
|
133
|
+
uses both for its zoom and screen controls.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
const controls = document.createElement('div')
|
|
137
|
+
mountPromptBox(document, bridge, { actions: controls, signOut: false })
|
|
138
|
+
```
|
|
139
|
+
|
|
130
140
|
Inside the visual editor, people who may edit get a prompt box at the bottom
|
|
131
141
|
of the page: they type what to change and it shows on the page right away,
|
|
132
142
|
unsaved, with undo. It acts on the selected block, or the whole entry. The
|
package/dist/bridge.d.mts
CHANGED
|
@@ -125,6 +125,7 @@ type PromptLabels = {
|
|
|
125
125
|
minimize: string;
|
|
126
126
|
expand: string;
|
|
127
127
|
scopeEntry: string;
|
|
128
|
+
scopeNoPage: string;
|
|
128
129
|
scopeBlock: string;
|
|
129
130
|
clearBlock: string;
|
|
130
131
|
working: string;
|
|
@@ -169,6 +170,8 @@ type PromptLabels = {
|
|
|
169
170
|
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
170
171
|
type PromptBoxOptions = {
|
|
171
172
|
labels?: Partial<PromptLabels> | undefined;
|
|
173
|
+
actions?: HTMLElement | undefined;
|
|
174
|
+
signOut?: boolean | undefined;
|
|
172
175
|
};
|
|
173
176
|
declare const mountPromptBox: (doc: Document, bridge: ContentBridge, options?: PromptBoxOptions) => () => void;
|
|
174
177
|
|
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,uBAAuB;AAC5B;AACA;AACA;AACA;AACA,KAAK,0BAA0B,GAAG,uBAAuB;AACzD,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,gBAAgB,WAAW;AAC3B;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,yBAAyB,WAAW;AACpC,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,sCAAsC,WAAW,GAAG,OAAO,CAAC,0BAA0B;AACtF;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;;ACjGxC,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;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;;
|
|
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,0BAA0B,GAAG,uBAAuB;AACzD,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,gBAAgB,WAAW;AAC3B;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,yBAAyB,WAAW;AACpC,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,sCAAsC,WAAW,GAAG,OAAO,CAAC,0BAA0B;AACtF;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;;ACjGxC,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;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC,cAAc,WAAW;AACzB;AACA;AACA,cAAc,cAAc,QAAQ,QAAQ,UAAU,aAAa,YAAY,gBAAgB;;AClD/F,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,6DAA6D,aAAa,KAAK,aAAa","names":[]}
|
package/dist/bridge.d.ts
CHANGED
|
@@ -125,6 +125,7 @@ type PromptLabels = {
|
|
|
125
125
|
minimize: string;
|
|
126
126
|
expand: string;
|
|
127
127
|
scopeEntry: string;
|
|
128
|
+
scopeNoPage: string;
|
|
128
129
|
scopeBlock: string;
|
|
129
130
|
clearBlock: string;
|
|
130
131
|
working: string;
|
|
@@ -169,6 +170,8 @@ type PromptLabels = {
|
|
|
169
170
|
declare const DEFAULT_PROMPT_LABELS: PromptLabels;
|
|
170
171
|
type PromptBoxOptions = {
|
|
171
172
|
labels?: Partial<PromptLabels> | undefined;
|
|
173
|
+
actions?: HTMLElement | undefined;
|
|
174
|
+
signOut?: boolean | undefined;
|
|
172
175
|
};
|
|
173
176
|
declare const mountPromptBox: (doc: Document, bridge: ContentBridge, options?: PromptBoxOptions) => () => void;
|
|
174
177
|
|
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,uBAAuB;AAC5B;AACA;AACA;AACA;AACA,KAAK,0BAA0B,GAAG,uBAAuB;AACzD,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,gBAAgB,WAAW;AAC3B;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,yBAAyB,WAAW;AACpC,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,sCAAsC,WAAW,GAAG,OAAO,CAAC,0BAA0B;AACtF;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;;ACjGxC,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;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;;
|
|
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,0BAA0B,GAAG,uBAAuB;AACzD,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,gBAAgB,WAAW;AAC3B;AACA,KAAK,aAAa;AAClB;AACA;AACA;AACA;AACA,sBAAsB,WAAW;AACjC,yBAAyB,WAAW;AACpC,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,sCAAsC,WAAW,GAAG,OAAO,CAAC,0BAA0B;AACtF;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;;ACjGxC,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;AACA;AACA;AACA;AACA;AACA,cAAc,qBAAqB,EAAE,YAAY;AACjD,KAAK,gBAAgB;AACrB,aAAa,OAAO,CAAC,YAAY;AACjC,cAAc,WAAW;AACzB;AACA;AACA,cAAc,cAAc,QAAQ,QAAQ,UAAU,aAAa,YAAY,gBAAgB;;AClD/F,KAAK,aAAa;AAClB;AACA,uBAAuB,gBAAgB;AACvC;AACA;AACA;AACA;AACA,cAAc,iBAAiB,QAAQ,aAAa;AACpD,cAAc,gBAAgB,6DAA6D,aAAa,KAAK,aAAa","names":[]}
|
package/dist/bridge.global.js
CHANGED
|
@@ -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
|
-
`,d=(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},c=/(-?\d*\.?\d+)(?:s|l|d)?vh\b/g,p=(e,t)=>(c.lastIndex=0,c.test(e))?e.replace(c,(e,r)=>`${Math.round(Number(r)*t/100*100)/100}px`):null,g=(e,t)=>{for(let r=0;r<e.length;r++){let o=e.item(r),n=p(e.getPropertyValue(o),t);null!==n&&e.setProperty(o,n,e.getPropertyPriority(o))}},u=(e,t)=>{for(let r of Array.from(e)){let{style:e,cssRules:o}=r;e&&g(e,t),o&&u(o,t)}},h="obelism-content-bridge",m="#d58a1f",b=(e="")=>`${e}[${t}]{cursor:pointer;transition:outline-color .15s}${e}[${t}]:hover{outline:2px dashed ${m};outline-offset:2px}${e}[${t}][data-cms-selected]{outline:2px solid ${m};outline-offset:2px}`,f={features:[],selectedUid:null,prompting:!1,canUndo:!1,unsaved:!1,saving:!1,publishing:!1,selecting:!1,stats:{},statsVisible:!1},v=()=>{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)}}}},y=()=>Promise.reject(Error("Save and publish in the visual editor itself")),x=()=>Promise.reject(Error("Only while signed in to edit on the site")),w={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")),createCollectionPage:()=>Promise.reject(Error("Collection pages are made on the site itself")),view:x,applyJson:x,openForm:(e,t={})=>(queueMicrotask(()=>t.onError?.("Only while signed in to edit on the site")),{close:()=>{}}),pages:x,openPage:()=>{},undo:()=>{},save:y,publish:y,signOut:()=>{},select:()=>{},setSelecting:()=>{}},k=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0,E=e=>`[${t}="${e.replace(/["\\]/g,"\\$&")}"]`,C=(e,t)=>{let r=v();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(a),product:null,collection: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:()=>f,...w,destroy:()=>{}}},P={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.",addCollectionPage:"Add a collection page",addingCollectionPage:"Making the collection page…",addedCollectionPage:"Opening the collection page…",collectionPageHint:"This collection has no page yet. Add one for what goes around its products."},A="obelism-content-prompt-side",L={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"/>',mark:'<path d="M12 3v18M3 12h18"/><g fill="currentColor" stroke="none"><circle cx="7" cy="7" r="1.75"/><circle cx="17" cy="7" r="1.75"/><circle cx="7" cy="17" r="1.75"/><circle cx="17" cy="17" r="1.75"/></g>',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"/>'},S=`
|
|
25
|
+
`,d=(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},c=/(-?\d*\.?\d+)(?:s|l|d)?vh\b/g,p=(e,t)=>(c.lastIndex=0,c.test(e))?e.replace(c,(e,r)=>`${Math.round(Number(r)*t/100*100)/100}px`):null,g=(e,t)=>{for(let r=0;r<e.length;r++){let o=e.item(r),n=p(e.getPropertyValue(o),t);null!==n&&e.setProperty(o,n,e.getPropertyPriority(o))}},u=(e,t)=>{for(let r of Array.from(e)){let{style:e,cssRules:o}=r;e&&g(e,t),o&&u(o,t)}},h="obelism-content-bridge",m="#d58a1f",b=(e="")=>`${e}[${t}]{cursor:pointer;transition:outline-color .15s}${e}[${t}]:hover{outline:2px dashed ${m};outline-offset:2px}${e}[${t}][data-cms-selected]{outline:2px solid ${m};outline-offset:2px}`,f={features:[],selectedUid:null,prompting:!1,canUndo:!1,unsaved:!1,saving:!1,publishing:!1,selecting:!1,stats:{},statsVisible:!1},v=()=>{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)}}}},y=()=>Promise.reject(Error("Save and publish in the visual editor itself")),x=()=>Promise.reject(Error("Only while signed in to edit on the site")),w={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")),createCollectionPage:()=>Promise.reject(Error("Collection pages are made on the site itself")),view:x,applyJson:x,openForm:(e,t={})=>(queueMicrotask(()=>t.onError?.("Only while signed in to edit on the site")),{close:()=>{}}),pages:x,openPage:()=>{},undo:()=>{},save:y,publish:y,signOut:()=>{},select:()=>{},setSelecting:()=>{}},k=e=>"number"==typeof e&&Number.isFinite(e)&&e>=0,E=e=>`[${t}="${e.replace(/["\\]/g,"\\$&")}"]`,C=(e,t)=>{let r=v();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(a),product:null,collection: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:()=>f,...w,destroy:()=>{}}},P={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",scopeNoPage:"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.",addCollectionPage:"Add a collection page",addingCollectionPage:"Making the collection page…",addedCollectionPage:"Opening the collection page…",collectionPageHint:"This collection has no page yet. Add one for what goes around its products."},A="obelism-content-prompt-side",L={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"/>',mark:'<path d="M12 3v18M3 12h18"/><g fill="currentColor" stroke="none"><circle cx="7" cy="7" r="1.75"/><circle cx="17" cy="7" r="1.75"/><circle cx="7" cy="17" r="1.75"/><circle cx="17" cy="17" r="1.75"/></g>',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"/>'},S=`
|
|
26
26
|
:host { all: initial; }
|
|
27
27
|
* { box-sizing: border-box; font: inherit; color: inherit; margin: 0; }
|
|
28
28
|
.root {
|
|
@@ -81,7 +81,7 @@ button:disabled { cursor: not-allowed; }
|
|
|
81
81
|
button:focus-visible { outline: 2px solid rgb(var(--theme-accent-rgb)); outline-offset: 2px; }
|
|
82
82
|
|
|
83
83
|
/* Closed: one floating pill that reads like an empty field, with the mark. */
|
|
84
|
-
.bar { display: flex; justify-content: center; }
|
|
84
|
+
.bar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
|
|
85
85
|
.pill {
|
|
86
86
|
display: flex; align-items: center; gap: 12px; width: min(560px, 100%); height: 56px;
|
|
87
87
|
padding: 0 22px 0 26px; border-radius: var(--border-radius-pill);
|
|
@@ -212,7 +212,7 @@ button.chip:disabled { opacity: .5; }
|
|
|
212
212
|
|
|
213
213
|
/* On the site: storing the draft, and the way out. */
|
|
214
214
|
.footer {
|
|
215
|
-
display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
215
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
216
216
|
border-top: 1px solid rgb(var(--theme-border-rgb) / .2);
|
|
217
217
|
background: rgb(var(--theme-background-actions-rgb) / .45);
|
|
218
218
|
}
|
|
@@ -257,4 +257,4 @@ button.chip:disabled { opacity: .5; }
|
|
|
257
257
|
.empty { padding: 8px 12px; color: rgb(var(--theme-foreground-muted-rgb)); }
|
|
258
258
|
.empty.error { color: var(--theme-error); }
|
|
259
259
|
[hidden] { display: none !important; }
|
|
260
|
-
`,N=(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},M=(e,t)=>{let r=N(e,"span",{className:"icon"});return r.setAttribute("aria-hidden","true"),r.innerHTML=`<svg viewBox="0 0 24 24">${L[t]}</svg>`,r},I=(e,t,r={})=>{let o,n={...P,...r.labels},a=N(e,"div");a.setAttribute("data-obelism-content-prompt","");let i=a.attachShadow({mode:"open"}),l="site"===t.mode,s=N(e,"span",{textContent:n.open}),d=N(e,"button",{className:"pill",type:"button"},s,((o=M(e,"mark")).classList.add("mark"),o)),c=N(e,"span",{className:"pill compact"},`${n.viewingDrafts} \xb7 `),p=N(e,"button",{className:"link",type:"button",textContent:n.signOut});c.appendChild(p);let g=N(e,"p",{className:"status"});g.setAttribute("role","status");let u=N(e,"textarea",{placeholder:n.placeholder,rows:1});u.setAttribute("aria-label",n.open);let h=N(e,"div",{className:"form-loader",textContent:n.formLoading});h.setAttribute("role","status");let m=N(e,"div",{className:"form"},h),b=M(e,"page"),f=M(e,"block"),v=N(e,"span"),y=N(e,"button",{type:"button",title:n.clearBlock});y.setAttribute("aria-label",n.clearBlock),y.appendChild(M(e,"close"));let x=N(e,"span",{className:"chip scope"},b,f,v,y),w=N(e,"button",{className:"action chip",type:"button"},M(e,"undo"),n.undo),k=t=>{let r=N(e,"button",{type:"button",textContent:t});return r.setAttribute("aria-pressed","false"),r},E=k(n.modePrompt),C=k(n.form),L=N(e,"span",{className:"modes"},E,C);L.setAttribute("role","group"),L.setAttribute("aria-label",n.modes);let I=N(e,"button",{className:"action chip",type:"button"},M(e,"newPage"),n.newPage),U=N(e,"button",{className:"action chip product",type:"button"},M(e,"newPage"),n.addProductPage),$=N(e,"button",{type:"button",title:n.newPageCancel});$.setAttribute("aria-label",n.newPageCancel),$.appendChild(M(e,"close"));let O=N(e,"span",{className:"chip scope"},M(e,"newPage"),N(e,"span",{textContent:n.newPage}),$),R=N(e,"input",{type:"text",placeholder:n.pathPlaceholder,autocomplete:"off",spellcheck:!1}),j=N(e,"label",{className:"path"},N(e,"span",{textContent:n.path}),R),z=N(e,"button",{className:"close icon-button",type:"button",title:n.close},M(e,"close"));z.setAttribute("aria-label",n.close);let T=M(e,"minimize"),D=M(e,"expand"),F=N(e,"button",{className:"icon-button",type:"button"},T,D),q=N(e,"button",{className:"action primary icon-button",type:"submit"},N(e,"span",{className:"visually-hidden",textContent:n.send}),M(e,"send"));q.title=n.send;let V=N(e,"span",{className:"divider"}),B=N(e,"div",{className:"toolbar"},x,O,L,w,U,I,N(e,"span",{className:"spacer"}),F,z,V,q),H=N(e,"span",{textContent:n.pages}),W=N(e,"button",{className:"chip page-chip",type:"button",title:n.pages},M(e,"page"),H,M(e,"chevrons"));W.setAttribute("aria-haspopup","listbox"),W.setAttribute("aria-expanded","false"),W.setAttribute("aria-controls","obelism-pages");let Y=N(e,"input",{type:"text",placeholder:n.pagesSearch,autocomplete:"off",spellcheck:!1});Y.setAttribute("role","combobox"),Y.setAttribute("aria-label",n.pagesSearch),Y.setAttribute("aria-autocomplete","list"),Y.setAttribute("aria-expanded","true"),Y.setAttribute("aria-controls","obelism-pages");let X=N(e,"ul",{className:"options",id:"obelism-pages"});X.setAttribute("role","listbox"),X.setAttribute("aria-label",n.pages);let _=N(e,"p",{className:"empty"}),J=N(e,"div",{className:"pages"},N(e,"label",{className:"search"},M(e,"search"),Y),X,_),Z=N(e,"span",{className:"unsaved"});Z.appendChild(N(e,"span",{className:"dot"})),Z.appendChild(e.createTextNode(n.unsaved));let K=N(e,"button",{className:"link",type:"button",textContent:n.signOut}),G=N(e,"button",{className:"action chip",type:"button",textContent:n.save}),Q=N(e,"button",{className:"action chip",type:"button",textContent:n.publish}),ee=N(e,"div",{className:"footer"},W,Z,N(e,"span",{className:"spacer"}),K,G,Q),et=N(e,"form",{className:"panel"},g,j,u,m,B,J,ee),er=N(e,"div",{className:"root"},N(e,"div",{className:"bar"},d,c),et);i.append(N(e,"style",{textContent:S}),er);let eo=e.defaultView,en=e=>{"center"===e?delete er.dataset.side:er.dataset.side=e};en((()=>{try{let e=eo?.localStorage.getItem(A);return"left"===e||"right"===e?e:"center"}catch{return"center"}})());let ea=null,ei=!1;er.addEventListener("pointerdown",e=>{if(ei=!1,0!==e.button||!e.isPrimary)return;let t=e.target.closest("button, input, textarea, iframe, a, label, .pages, .form");if(t&&t!==d)return;let{left:r,right:o}=er.getBoundingClientRect();ea={id:e.pointerId,startX:e.clientX,x:e.clientX,velocity:0,time:e.timeStamp,moved:!1,min:Math.min(0,16-r),max:Math.max(0,(eo?.innerWidth??0)-16-o)}}),er.addEventListener("pointermove",e=>{if(!ea||e.pointerId!==ea.id)return;let t=e.clientX-ea.startX;if(!ea.moved){if(6>Math.abs(t))return;ea.moved=!0,er.classList.add("dragging");try{er.setPointerCapture(e.pointerId)}catch{}}let r=e.timeStamp-ea.time;r>0&&(ea.velocity=(e.clientX-ea.x)/r),ea.x=e.clientX,ea.time=e.timeStamp;let o=Math.min(Math.max(t,ea.min),ea.max);er.style.translate=`${o+(t-o)/3}px 0`});let el=e=>{if(!ea||e.pointerId!==ea.id)return;let{moved:t,x:r,velocity:o,time:n}=ea;if(ea=null,!t)return;ei=!0;let a=er.getBoundingClientRect().left,i=eo?.innerWidth??0,l=r+(e.timeStamp-n>80?0:Math.min(Math.max(150*o,-120),120)),s=l<i/3?"left":l>2*i/3?"right":"center";en(s),er.style.translate="";let d=er.getBoundingClientRect().left;er.style.translate=`${a-d}px 0`,er.offsetWidth,er.classList.remove("dragging"),er.style.translate="";try{eo?.localStorage.setItem(A,s)}catch{}};er.addEventListener("pointerup",el),er.addEventListener("pointercancel",el),er.addEventListener("click",e=>{ei&&(ei=!1,e.preventDefault(),e.stopPropagation())},!0);let es=!1,ed=!1,ec=!1,ep=null,eg=!1,eu=null,eh=!1,em=!1,eb=null,ef=null,ev=null,ey=0,ex=e=>({text:e instanceof Error?e.message:String(e),error:!0}),ew=e=>{let r=e.features.includes("prompt"),o=e.saving||e.publishing,a=e.prompting||o;er.hidden=!r&&!l,d.hidden=es||!r,c.hidden=r||!l,et.hidden=!es||!r;let i=l&&e.features.includes("create"),p=l&&null===t.entryId,k=p&&i?t.product?"product":t.collection?"collection":null:null,P=null!==k,A="collection"===k?{add:n.addCollectionPage,adding:n.addingCollectionPage,hint:n.collectionPageHint}:{add:n.addProductPage,adding:n.addingProductPage,hint:n.productPageHint};U.lastChild.textContent=A.add;let S=p&&i&&!P;i||(ec=!1),S&&(ec=!0),(ec||p||!l)&&(eg=!1);let N=es&&r&⪚N&&!eu?eC():!N&&eu&&eP();let M=P&&!ec;s.textContent=M?A.add:S?n.newPage:n.open,$.hidden=S,x.hidden=ec||M,O.hidden=!ec,U.hidden=!M,U.disabled=a,I.hidden=ec||eg||!i,I.disabled=a,ed&&(em=!1),j.hidden=!ec||em||ed,R.disabled=a,u.hidden=eg||em||ed||M,m.hidden=!eg||em||ed,m.classList.toggle("loading",eh),h.hidden=!eh,B.hidden=em,J.hidden=!em,u.placeholder=ec?n.newPagePlaceholder:n.placeholder,v.textContent=e.selectedUid?n.scopeBlock:n.scopeEntry,y.hidden=!e.selectedUid,b.hidden=!!e.selectedUid,f.hidden=!e.selectedUid,L.hidden=!l||ec||p||!e.features.includes("form"),E.setAttribute("aria-pressed",String(!eg)),C.setAttribute("aria-pressed",String(eg)),L.querySelectorAll("button").forEach(e=>{e.disabled=a}),w.hidden=ec||!e.canUndo,w.disabled=a,q.hidden=eg||ed||M,V.hidden=eg||ed||M;let z=ed?n.expand:n.minimize;F.title=z,F.setAttribute("aria-label",z),F.setAttribute("aria-expanded",String(!ed)),T.hidden=ed,D.hidden=!ed,q.disabled=a||""===u.value.trim()||ec&&""===R.value.trim(),u.disabled=a,G.hidden=!e.features.includes("save")||p,G.disabled=a||!e.unsaved,G.textContent=e.saving?n.saving:n.save,Q.hidden=!e.features.includes("publish")||p,Q.disabled=a,Q.textContent=e.publishing?n.publishing:n.publish,K.hidden=!l,ee.hidden=!l,Z.hidden=!e.unsaved,W.hidden=!l,W.setAttribute("aria-expanded",String(em)),H.textContent=eb?.find(({entryId:e})=>e===t.entryId)?.name??n.pages;let Y=eg&&eh&&!em,X=e.prompting,_=e.prompting?ec?n.creating:M?A.adding:n.working:Y?"":ep?.text??(M?A.hint:!l||ec||em||e.selectedUid?"":n.selectHint);g.textContent=_,g.hidden=!_||ed,g.className=`status${X?" working":""}${!a&&!Y&&ep?.error?" error":""}`},ek=()=>ew(t.getState()),eE=()=>{u.style.height="auto",u.style.height=`${u.scrollHeight}px`},eC=()=>{eh=!0,m.classList.add("loading");let e=t.openForm(m,{title:n.formTitle,onReady:()=>{eu===e&&(eh=!1,ep=null,ek())},onError:t=>{eu===e&&(eh=!1,ep={text:t,error:!0},ek())}});eu=e},eP=()=>{eu?.close(),eu=null,eh=!1},eA=e=>{eg!==e&&(eg=e,ep=null,ek(),eg||u.focus())},eL=async()=>{if(eg)return;let e=u.value.trim();if(e&&!t.getState().prompting){ep=null;try{if(ec){let r=R.value.trim();if(!r)return R.focus();await t.createPage(r,e),eb=null,ef=null,ep={text:n.created,error:!1}}else{let{summary:r}=await t.prompt(e);ep={text:r,error:!1}}u.value="",eE()}catch(e){ep=ex(e)}ek(),u.focus()}},eS=()=>(ef??(ef=t.pages().then(e=>{eb=e,ev=null,eM(),ek()},e=>{ef=null,ev=ex(e).text,eM()})),ef),eN=()=>{let e=Y.value.trim().toLowerCase();return(eb??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},eM=()=>{let r=eN();ey=Math.max(0,Math.min(ey,r.length-1)),X.textContent="",r.forEach((r,o)=>{let a=r.entryId===t.entryId,i=N(e,"li",{className:`option${o===ey?" active":""}`,id:`obelism-page-${o}`},N(e,"span",{className:"option-text"},N(e,"span",{textContent:r.name}),N(e,"span",{className:"option-path",textContent:r.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(o===ey)),"published"!==r.status&&i.appendChild(N(e,"span",{className:"badge",textContent:"draft"===r.status?n.pageDraft:n.pageChanged})),a){i.setAttribute("aria-current","page");let t=M(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",n.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>eU(r)),X.appendChild(i)});let o=X.children[ey];o?(Y.setAttribute("aria-activedescendant",o.id),o.scrollIntoView?.({block:"nearest"})):Y.removeAttribute("aria-activedescendant"),_.textContent=(ev??(eb?"":n.pagesLoading))||(0===r.length?n.pagesEmpty:""),_.hidden=!_.textContent,_.className=`empty${ev?" error":""}`},eI=e=>{ep=null,(em=e)&&(Y.value="",ey=Math.max(0,(eb??[]).findIndex(({entryId:e})=>e===t.entryId)),eS(),eM()),ek(),(em?Y:W).focus()},eU=e=>{if(e.entryId===t.entryId)return eI(!1);t.openPage(e)},e$=e=>{(es=e)||(em=!1,ed=!1),ek(),l&&t.setSelecting(es&&!ec),es&&l&&eS()},eO=e=>{ec=e,ep=null,t.setSelecting(es&&!ec),ec&&t.select(null),ek(),(ec?R:u).focus()},eR=async e=>{ep=null;try{await t[e](),ep={text:"save"===e?n.saved:n.published,error:!1}}catch(e){ep=ex(e)}ek()};d.addEventListener("click",()=>{e$(!0),eg||(ec?R:u).focus()}),z.addEventListener("click",()=>e$(!1)),F.addEventListener("click",()=>{ed=!ed,ek(),ed||(eg?F:u).focus()}),et.addEventListener("click",e=>{if(!ed)return;let t=e.target.closest("button");t&&t!==F&&t!==z&&(ed=!1,ek())},!0),G.addEventListener("click",()=>void eR("save")),Q.addEventListener("click",()=>void eR("publish")),K.addEventListener("click",()=>t.signOut()),p.addEventListener("click",()=>t.signOut()),y.addEventListener("click",()=>t.select(null)),I.addEventListener("click",()=>eO(!0)),U.addEventListener("click",async()=>{ep=null;try{t.product?(await t.createProductPage(),ep={text:n.addedProductPage,error:!1}):(await t.createCollectionPage(),ep={text:n.addedCollectionPage,error:!1})}catch(e){ep=ex(e)}ek()}),$.addEventListener("click",()=>eO(!1)),E.addEventListener("click",()=>eA(!1)),C.addEventListener("click",()=>eA(!0)),W.addEventListener("click",()=>eI(!em)),R.addEventListener("input",ek),R.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing?"Escape"===e.key&&e$(!1):(e.preventDefault(),u.focus())}),Y.addEventListener("input",()=>{ey=0,eM()}),Y.addEventListener("keydown",e=>{let t=X.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;ey=(ey+("ArrowDown"===e.key?1:-1)+t)%t,eM()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),eI(!1));else{e.preventDefault();let t=eN()[ey];t&&eU(t)}}),w.addEventListener("click",()=>{ep=null,t.undo()}),et.addEventListener("submit",e=>{e.preventDefault(),eL()}),u.addEventListener("input",()=>{eE(),ek()}),u.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing?"Escape"===e.key&&e$(!1):(e.preventDefault(),eL())});let ej=t.on("change",ew);return ek(),e.body.appendChild(a),()=>{ej(),eP(),a.remove()}},U="https://content.obelism.studio",$=(e,t)=>JSON.stringify(e)===JSON.stringify(t),O=Symbol.for("@obelism/content/bridge"),R=C({isEditing:!1,entryId:null,on:()=>{}},new URLSearchParams),j=({url:e,prompt:c=!0,pagePath:p,productPath:m,collectionPath:y}={})=>{let x;if("u"<typeof window)return R;let P=window;if(P[O])return P[O];if(P.ObelismBridge)x=C(P.ObelismBridge,new URLSearchParams(P.location.search));else{let C=(x=((e,r)=>{let o,n,c,p,m,y=new URLSearchParams(e.location.search),x=e.parent!==e&&y.has("cms_preview"),C=v(),P=[],A={...f,selecting:!0},L=e=>{A={...A,...e},C.emit("change",A)},S={isEditing:x,mode:x?"editor":null,entryId:y.get("cms_entry"),environment:y.get(a),product:null,collection:null,on:C.on,getState:()=>A,...w,destroy:()=>{P.splice(0).forEach(e=>e())}};if(!x)return S;let N=e.document,M=(t,o={})=>{e.parent.postMessage({source:h,type:t,...o},r)},I=N.createElement("style");I.textContent=b(),N.head.appendChild(I),P.push(()=>I.remove());let U=(e,t)=>{if(N.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),A.selectedUid!==(e??null)&&L({selectedUid:e??null}),!e)return;let r=N.querySelector(E(e));r&&(r.setAttribute("data-cms-selected",""),t&&r.scrollIntoView({behavior:"smooth",block:"center"}))},$=e=>{let r=e.target,o=r?.closest?.(`[${t}]`);if(!o)return;e.preventDefault(),e.stopPropagation();let n=o.getAttribute(t);U(n,!1),M("select",{uid:n})};N.addEventListener("click",$,!0),P.push(()=>N.removeEventListener("click",$,!0));let O=()=>Math.ceil(Math.max(N.documentElement.scrollHeight,N.body?.scrollHeight??0)),R=0,j=()=>{R=O(),M("ready",{url:e.location.href,height:R})},z=e.ResizeObserver;if("function"==typeof z){let e=new z(()=>{let e=O();e!==R&&(R=e,M("size",{height:e}))});e.observe(N.documentElement),N.body&&e.observe(N.body),P.push(()=>e.disconnect())}let T=new Map,D=0,F=e=>{let t=T.get(e);return t?(clearTimeout(t.timer),T.delete(e),0===T.size&&L({prompting:!1}),t):null};S.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!A.features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let o=`prompt_${++D}`,n=void 0===t.uid?A.selectedUid:t.uid;return new Promise((e,t)=>{let a=setTimeout(()=>{F(o)?.reject(Error("The editor did not answer in time"))},12e4);T.set(o,{resolve:e,reject:t,timer:a}),L({prompting:!0}),M("prompt",{id:o,prompt:r,uid:n})})},S.undo=()=>M("undo"),S.select=e=>{U(e,!1),M("select",{uid:e})};let q=null;P.push(()=>q?.destroy()),P.push(()=>{for(let e of T.keys())F(e)?.reject(Error("The bridge was destroyed"))});let V=(o=new WeakSet,n=null,c=null,p=!1,m=()=>{if(null!==n){for(let e of Array.from(N.styleSheets)){let t;if(!o.has(e)){try{t=e.cssRules}catch{continue}o.add(e),u(t,n)}}N.querySelectorAll('[style*="vh"]').forEach(e=>{g(e.style,n)})}},{freeze(e){if(null!==n||!(e>0))return;n=e,m();let t=N.defaultView?.MutationObserver;t&&(c=new t(()=>{if(p)return;p=!0;let e=()=>{p=!1,m()};N.defaultView?.requestAnimationFrame?N.defaultView.requestAnimationFrame(e):e()})).observe(N.documentElement,{childList:!0,subtree:!0})},destroy(){c?.disconnect()}});P.push(()=>V.destroy());let B=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)j();else if("update"===o.type&&o.entry)C.emit("update",{entry:o.entry,selectedUid:o.selectedUid??null}),e.requestAnimationFrame(()=>U(o.selectedUid,!1)),q?.refresh();else if("select"===o.type)U(o.uid,!0);else if("saved"===o.type||"published"===o.type)C.emit(o.type,{}),0===C.listeners.update.size&&e.location.reload();else if("features"===o.type&&Array.isArray(o.features))L({features:o.features.filter(e=>"string"==typeof e)});else if("stats"===o.type)L({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??{};k(e)&&k(n)&&k(a)&&k(i)&&(t[r]={clicks:e,clickers:n,viewers:a,rate:i})}return t})(o.stats),statsVisible:!1!==o.visible}),(q||Object.keys(A.stats).length)&&(q??(q=((e,{selector:t,onSelect:r,labels:o})=>{let n=e.document,a={...i,...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={},m=!1,b=null,f=()=>{if(b=null,u.replaceChildren(),u.hidden=!m,!m)return;let o=e.innerHeight;for(let[i,s]of Object.entries(h)){let c=n.querySelector(t(i));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=i,g.textContent=l(a.clicked,{rate:Math.round(100*s.rate)}),g.title=l(a.title,{clickers:s.clickers,viewers:s.viewers,clicks:s.clicks});let{place:h,top:m,left:b}=d(p,e.innerWidth);g.dataset.place=h,g.style.top=`${m}px`,g.style.left=`${b}px`,g.addEventListener("click",()=>r(i)),u.appendChild(g)}},v=()=>{null===b&&m&&(b=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,m=r,null!==b&&(e.cancelAnimationFrame?.(b),b=null),f()},refresh:v,destroy(){null!==b&&e.cancelAnimationFrame?.(b),e.removeEventListener("scroll",v,{capture:!0}),e.removeEventListener("resize",v),x?.disconnect(),c.remove()}}})(e,{selector:E,onSelect:e=>S.select(e)})),q.update(A.stats,A.statsVisible));else if("viewport"===o.type&&"number"==typeof o.height)V.freeze(o.height);else if("promptState"===o.type)L({canUndo:!0===o.canUndo});else if("promptResult"===o.type&&"string"==typeof o.id){let e=F(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),P.push(()=>e.removeEventListener("message",B)),"loading"===N.readyState?(N.addEventListener("DOMContentLoaded",j,{once:!0}),P.push(()=>N.removeEventListener("DOMContentLoaded",j))):j(),S})(P,new URL(e||U).origin)).isEditing||P.parent!==P?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})(P.document);if(C&&(x=((e,a,{pagePath:i=e=>`/${e}`,productPath:l,collectionPath:s}={})=>{let d=e.document,c=v(),p=[],g=new Map,u=[],m=new Set,y=null,x=null,w=-1/0,k=new Map,C=f,P=e=>{C={...C,...e},c.emit("change",C)},A=()=>P({unsaved:[...g.values()].some(({content:e,saved:t})=>!$(e,t)),canUndo:u.length>0}),L=async(t,r)=>{let o=await e.fetch(`${a}/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)}),n=await o.json().catch(()=>({}));if(401===o.status)throw P({features:[]}),Error("You were signed out. Sign in again to edit.");if(!o.ok)throw Error("string"==typeof n.error?n.error:`Obelism Content answered ${o.status}`);return n},S=()=>d.querySelector(`[${r}]`)?.getAttribute(r)??null,N=()=>{let e=d.querySelector(`[${o}]`),t=e?.getAttribute(o),r=e?.getAttribute("data-cms-product-handle");return t&&r?{id:t,handle:r}:null},M=()=>{let e=d.querySelector(`[${n}]`),t=e?.getAttribute(n),r=e?.getAttribute("data-cms-collection-handle");return t&&r?{id:t,handle:r}:null},I=e=>{let t=e?d.querySelector(E(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??S()},U=()=>{if(!y)return;let e=y.space.locales.map(({code:e})=>e),t=d.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:y.space.defaultLocale},O=new Map,R=async e=>{let t=g.get(e);if(t)return t;let r=O.get(e);return r||(r=L(`entries/${encodeURIComponent(e)}`).then(t=>{let r=g.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return g.set(e,r),r}).finally(()=>O.delete(e)),O.set(e,r)),r},j=e=>{let t=void 0===e?C.selectedUid:e,r=I(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},z=e=>{d.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),C.selectedUid!==e&&P({selectedUid:e}),e&&d.querySelector(E(e))?.setAttribute("data-cms-selected","")},T=async t=>{if(0===c.listeners.update.size)return;let r=g.get(t)?.content,{entry:o}=await L(`entries/${encodeURIComponent(t)}/preview`,{content:r,locale:U()});c.emit("update",{entry:o,selectedUid:C.selectedUid}),e.requestAnimationFrame(()=>z(C.selectedUid))},D=e=>console.error("[@obelism/content bridge]",e),F=t=>{c.emit(t,{}),0===c.listeners.update.size&&e.location.reload()},q=async()=>{for(let[e,t]of g){if($(t.content,t.saved))continue;let{draftRevision:r}=await L(`entries/${encodeURIComponent(e)}/save`,{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,m.add(e)}u.length=0,w=-1/0,A()},V={isEditing:!0,mode:"site",get entryId(){return S()},get product(){return N()},get collection(){return M()},environment:null,on:c.on,getState:()=>C,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!C.features.includes("prompt"))throw Error("You may not edit content here");let{uid:o,entryId:n}=j(t.uid);P({prompting:!0});try{let e=await R(n),t=await L(`entries/${encodeURIComponent(n)}/prompt`,{prompt:r,content:e.content,locale:U(),uid:o});return u.push({entryId:n,content:e.content}),w=-1/0,e.content=t.content,A(),await T(n),{summary:t.summary}}finally{P({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(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("entries",{path:t,prompt:o,locale:U(),from:S()}),n=i(r.path,U()??"");return e.location.assign(n),{summary:r.summary,entryId:r.entryId,path:r.path,url:n}}finally{P({prompting:!1})}},async createProductPage(t=N()??void 0){if(!t)throw Error("Nothing on this page is marked as a product: add editableProduct(product)");if(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("product-pages",{product:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{P({prompting:!1})}},async createCollectionPage(t=M()??void 0){if(!t)throw Error("Nothing on this page is marked as a collection: add editableCollection(collection)");if(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("collection-pages",{collection:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{P({prompting:!1})}},async view(e={}){let{uid:t,entryId:r}=j(e.uid),o=await R(r),{view:n}=await L(`entries/${encodeURIComponent(r)}/view`,{content:o.content,locale:U(),uid:t});return n},async applyJson(e,t={}){if(!C.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}=j(t.uid);P({prompting:!0});try{let t=await R(o),n=await L(`entries/${encodeURIComponent(o)}/apply`,{changes:e,content:t.content,locale:U(),uid:r});return $(n.content,t.content)||(u.push({entryId:o,content:t.content}),w=-1/0,t.content=n.content,A(),await T(o)),{changed:n.changed??[],...n.view&&{view:n.view}}}finally{P({prompting:!1})}},openForm(t,r={}){let{title:o="Content form",onReady:n,onError:a}=r;x?.();let i=!1,l=null,s=null,d=()=>{},p=e=>{i||a?.(e instanceof Error?e.message:String(e))},m=()=>{i||(i=!0,d(),l?.destroy(),x===m&&(x=null))};x=m;let b=()=>{if(i||!l)return;let e=I(C.selectedUid);if(!e)return;let t=g.get(e);if(!t)return void R(e).then(b,p);let r={entryId:e,content:t.content,locale:U(),selectedUid:C.selectedUid};s&&s.entryId===r.entryId&&s.content===r.content&&s.locale===r.locale&&s.selectedUid===r.selectedUid||(s=r,l.show(r))},f=(e,t)=>{let r=t??s?.entryId,o=void 0===r?void 0:g.get(r);if(i||void 0===r||!o||$(e,o.content))return;let n=Date.now();n-w>=1e3&&u.push({entryId:r,content:o.content}),w=n,o.content=e,s?.entryId===r&&(s={...s,content:e}),A(),clearTimeout(k.get(r)),k.set(r,setTimeout(()=>{k.delete(r),T(r).catch(D)},300))};return(async()=>{if(!C.features.includes("form"))throw Error("You may not edit content here");await R(j(void 0).entryId);let{url:r}=await L("form",{});i||(l=((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,l=t.ownerDocument.createElement("iframe");l.title=o,l.src=r;let s=!1,d=!1,c=null,p=()=>{s&&c&&l.contentWindow?.postMessage({source:h,type:"content",...c},i)},g=setTimeout(()=>{d||n.onError("The form did not open")},3e4),u=()=>{d=!0,clearTimeout(g),n.onReady()},m=e=>{if(e.origin!==i||!l.contentWindow||e.source!==l.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)s=!0,p(),!0!==t.loading&&u();else if("loaded"===t.type)s&&u();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));l.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",m),t.appendChild(l),{show(e){c=e,p()},destroy(){clearTimeout(g),e.removeEventListener("message",m),l.remove()}}})(e,t,"string"==typeof r?r:"",o,{onReady:()=>n?.(),onChange:f,onError:e=>a?.(e)}),d=c.on("change",b),b())})().catch(p),{close:m}},async pages(){let{pages:e}=await L("pages"),t=[U(),y?.space.defaultLocale];return e.flatMap(e=>{let r,o,n=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],a=void 0===n?void 0:e.paths[n];return void 0===n||void 0===a?[]:[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:a,url:e.product?(r=e.product.handle,l?l(r,n):(y?.productPath??"/products/{handle}").replaceAll("{handle}",encodeURIComponent(r))):e.collection?(o=e.collection.handle,s?s(o,n):(y?.collectionPath??"/collections/{handle}").replaceAll("{handle}",encodeURIComponent(o))):i(a,n),product:e.product??null,collection:e.collection??null}]})},openPage(t){(!C.unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(g.clear(),u.length=0,A(),e.location.assign(t.url))},undo(){let e=u.pop(),t=e&&g.get(e.entryId);e&&t&&(w=-1/0,t.content=e.content,A(),T(e.entryId).catch(D))},async save(){if(!C.features.includes("save"))throw Error("You may not edit content here");P({saving:!0});try{await q()}finally{P({saving:!1})}F("saved")},async publish(){if(!C.features.includes("publish"))throw Error("You may not publish here");P({publishing:!0});try{await q();let e=S(),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 L(`entries/${encodeURIComponent(e)}/publish`,{}),m.delete(e)}finally{P({publishing:!1})}F("published")},signOut(){if(C.unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;g.clear(),A();let t=e.location.pathname+e.location.search;e.location.href=`${a}/logout?return_to=${encodeURIComponent(t)}`},select(e){z(e)},setSelecting(e){e?d.documentElement.setAttribute("data-cms-selecting",""):d.documentElement.removeAttribute("data-cms-selecting"),P({selecting:e})},destroy(){x?.(),k.forEach(e=>clearTimeout(e)),k.clear(),p.splice(0).forEach(e=>e())}},B=d.createElement("style");B.textContent=b("html[data-cms-selecting] "),d.head.appendChild(B),p.push(()=>B.remove()),p.push(()=>d.documentElement.removeAttribute("data-cms-selecting"));let H=e=>{if(!C.selecting)return;let r=e.target,o=r?.closest?.(`[${t}]`);o&&(e.preventDefault(),e.stopPropagation(),z(o.getAttribute(t)))};d.addEventListener("click",H,!0),p.push(()=>d.removeEventListener("click",H,!0));let W=e=>{C.unsaved&&(e.preventDefault(),e.returnValue="")};return e.addEventListener("beforeunload",W),p.push(()=>e.removeEventListener("beforeunload",W)),L("session").then(e=>{y=e,P({features:e.features})}).catch(e=>console.error("[@obelism/content bridge]",e)),V})(P,C,{pagePath:p,productPath:m,collectionPath:y})),x.isEditing&&c){let e=P.document,t=()=>{},r=!1,o=()=>{r||(t=I(e,x,!0===c?{}:c))};e.body?o():e.addEventListener("DOMContentLoaded",o,{once:!0});let n=x.destroy;x.destroy=()=>{r=!0,e.removeEventListener("DOMContentLoaded",o),t(),n()}}}return P[O]=x,x};(e=window).ObelismBridge=j((e=>{let t=e?.dataset.url,r=t||U;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:j,mountPromptBox:I}}();
|
|
260
|
+
`,N=(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},M=(e,t)=>{let r=N(e,"span",{className:"icon"});return r.setAttribute("aria-hidden","true"),r.innerHTML=`<svg viewBox="0 0 24 24">${L[t]}</svg>`,r},I=(e,t,r={})=>{let o,n={...P,...r.labels},a=N(e,"div");a.setAttribute("data-obelism-content-prompt","");let i=a.attachShadow({mode:"open"}),l="site"===t.mode,s=N(e,"span",{textContent:n.open}),d=N(e,"button",{className:"pill",type:"button"},s,((o=M(e,"mark")).classList.add("mark"),o)),c=N(e,"span",{className:"pill compact"},`${n.viewingDrafts} \xb7 `),p=N(e,"button",{className:"link",type:"button",textContent:n.signOut});c.appendChild(p);let g=N(e,"p",{className:"status"});g.setAttribute("role","status");let u=N(e,"textarea",{placeholder:n.placeholder,rows:1});u.setAttribute("aria-label",n.open);let h=N(e,"div",{className:"form-loader",textContent:n.formLoading});h.setAttribute("role","status");let m=N(e,"div",{className:"form"},h),b=M(e,"page"),f=M(e,"block"),v=N(e,"span"),y=N(e,"button",{type:"button",title:n.clearBlock});y.setAttribute("aria-label",n.clearBlock),y.appendChild(M(e,"close"));let x=N(e,"span",{className:"chip scope"},b,f,v,y),w=N(e,"button",{className:"action chip",type:"button"},M(e,"undo"),n.undo),k=t=>{let r=N(e,"button",{type:"button",textContent:t});return r.setAttribute("aria-pressed","false"),r},E=k(n.modePrompt),C=k(n.form),L=N(e,"span",{className:"modes"},E,C);L.setAttribute("role","group"),L.setAttribute("aria-label",n.modes);let I=N(e,"button",{className:"action chip",type:"button"},M(e,"newPage"),n.newPage),U=N(e,"button",{className:"action chip product",type:"button"},M(e,"newPage"),n.addProductPage),$=N(e,"button",{type:"button",title:n.newPageCancel});$.setAttribute("aria-label",n.newPageCancel),$.appendChild(M(e,"close"));let O=N(e,"span",{className:"chip scope"},M(e,"newPage"),N(e,"span",{textContent:n.newPage}),$),R=N(e,"input",{type:"text",placeholder:n.pathPlaceholder,autocomplete:"off",spellcheck:!1}),j=N(e,"label",{className:"path"},N(e,"span",{textContent:n.path}),R),z=N(e,"button",{className:"close icon-button",type:"button",title:n.close},M(e,"close"));z.setAttribute("aria-label",n.close);let T=M(e,"minimize"),D=M(e,"expand"),F=N(e,"button",{className:"icon-button",type:"button"},T,D),q=N(e,"button",{className:"action primary icon-button",type:"submit"},N(e,"span",{className:"visually-hidden",textContent:n.send}),M(e,"send"));q.title=n.send;let V=N(e,"span",{className:"divider"}),B=N(e,"div",{className:"toolbar"},x,O,L,w,U,I,N(e,"span",{className:"spacer"}),F,z,V,q),H=N(e,"span",{textContent:n.pages}),W=N(e,"button",{className:"chip page-chip",type:"button",title:n.pages},M(e,"page"),H,M(e,"chevrons"));W.setAttribute("aria-haspopup","listbox"),W.setAttribute("aria-expanded","false"),W.setAttribute("aria-controls","obelism-pages");let Y=N(e,"input",{type:"text",placeholder:n.pagesSearch,autocomplete:"off",spellcheck:!1});Y.setAttribute("role","combobox"),Y.setAttribute("aria-label",n.pagesSearch),Y.setAttribute("aria-autocomplete","list"),Y.setAttribute("aria-expanded","true"),Y.setAttribute("aria-controls","obelism-pages");let X=N(e,"ul",{className:"options",id:"obelism-pages"});X.setAttribute("role","listbox"),X.setAttribute("aria-label",n.pages);let _=N(e,"p",{className:"empty"}),J=N(e,"div",{className:"pages"},N(e,"label",{className:"search"},M(e,"search"),Y),X,_),Z=N(e,"slot");Z.name="actions-footer";let K=N(e,"slot");K.name="actions-bar",r.actions&&(r.actions.slot="actions-bar",a.appendChild(r.actions));let G=N(e,"span",{className:"unsaved"});G.appendChild(N(e,"span",{className:"dot"})),G.appendChild(e.createTextNode(n.unsaved));let Q=N(e,"button",{className:"link",type:"button",textContent:n.signOut}),ee=N(e,"button",{className:"action chip",type:"button",textContent:n.save}),et=N(e,"button",{className:"action chip",type:"button",textContent:n.publish}),er=N(e,"div",{className:"footer"},W,G,N(e,"span",{className:"spacer"}),Z,Q,ee,et),eo=N(e,"form",{className:"panel"},g,j,u,m,B,J,er),en=N(e,"div",{className:"root"},N(e,"div",{className:"bar"},d,c,K),eo);i.append(N(e,"style",{textContent:S}),en);let ea=e.defaultView,ei=e=>{"center"===e?delete en.dataset.side:en.dataset.side=e};ei((()=>{try{let e=ea?.localStorage.getItem(A);return"left"===e||"right"===e?e:"center"}catch{return"center"}})());let el=null,es=!1;en.addEventListener("pointerdown",e=>{if(es=!1,0!==e.button||!e.isPrimary)return;let t=e.target.closest("button, input, textarea, select, iframe, a, label, .pages, .form");if(t&&t!==d)return;let{left:r,right:o}=en.getBoundingClientRect();el={id:e.pointerId,startX:e.clientX,x:e.clientX,velocity:0,time:e.timeStamp,moved:!1,min:Math.min(0,16-r),max:Math.max(0,(ea?.innerWidth??0)-16-o)}}),en.addEventListener("pointermove",e=>{if(!el||e.pointerId!==el.id)return;let t=e.clientX-el.startX;if(!el.moved){if(6>Math.abs(t))return;el.moved=!0,en.classList.add("dragging");try{en.setPointerCapture(e.pointerId)}catch{}}let r=e.timeStamp-el.time;r>0&&(el.velocity=(e.clientX-el.x)/r),el.x=e.clientX,el.time=e.timeStamp;let o=Math.min(Math.max(t,el.min),el.max);en.style.translate=`${o+(t-o)/3}px 0`});let ed=e=>{if(!el||e.pointerId!==el.id)return;let{moved:t,x:r,velocity:o,time:n}=el;if(el=null,!t)return;es=!0;let a=en.getBoundingClientRect().left,i=ea?.innerWidth??0,l=r+(e.timeStamp-n>80?0:Math.min(Math.max(150*o,-120),120)),s=l<i/3?"left":l>2*i/3?"right":"center";ei(s),en.style.translate="";let d=en.getBoundingClientRect().left;en.style.translate=`${a-d}px 0`,en.offsetWidth,en.classList.remove("dragging"),en.style.translate="";try{ea?.localStorage.setItem(A,s)}catch{}};en.addEventListener("pointerup",ed),en.addEventListener("pointercancel",ed),en.addEventListener("click",e=>{es&&(es=!1,e.preventDefault(),e.stopPropagation())},!0);let ec=!1,ep=!1,eg=!1,eu=null,eh=!1,em=null,eb=!1,ef=!1,ev=null,ey=null,ex=null,ew=0,ek=e=>({text:e instanceof Error?e.message:String(e),error:!0}),eE=e=>{let o=e.features.includes("prompt"),a=e.saving||e.publishing,i=e.prompting||a;en.hidden=!o&&!l,d.hidden=ec||!o,c.hidden=o||!l,eo.hidden=!ec||!o;let k=l&&e.features.includes("create"),P=l&&null===t.entryId,A=P&&k?t.product?"product":t.collection?"collection":null:null,S=null!==A,N="collection"===A?{add:n.addCollectionPage,adding:n.addingCollectionPage,hint:n.collectionPageHint}:{add:n.addProductPage,adding:n.addingProductPage,hint:n.productPageHint};U.lastChild.textContent=N.add;let M=P&&k&&!S;k||(eg=!1),M&&(eg=!0),(eg||P||!l)&&(eh=!1);let z=ec&&o&&eh;z&&!em?eA():!z&&em&&eL();let Y=S&&!eg;s.textContent=Y?N.add:M?n.newPage:n.open,$.hidden=M,x.hidden=eg||Y,O.hidden=!eg,U.hidden=!Y,U.disabled=i,I.hidden=eg||eh||!k,I.disabled=i,ep&&(ef=!1),j.hidden=!eg||ef||ep,R.disabled=i,u.hidden=eh||ef||ep||Y,m.hidden=!eh||ef||ep,m.classList.toggle("loading",eb),h.hidden=!eb,B.hidden=ef,J.hidden=!ef,u.placeholder=eg?n.newPagePlaceholder:n.placeholder,v.textContent=e.selectedUid?n.scopeBlock:P?n.scopeNoPage:n.scopeEntry,y.hidden=!e.selectedUid,b.hidden=!!e.selectedUid,f.hidden=!e.selectedUid,L.hidden=!l||eg||P||!e.features.includes("form"),E.setAttribute("aria-pressed",String(!eh)),C.setAttribute("aria-pressed",String(eh)),L.querySelectorAll("button").forEach(e=>{e.disabled=i}),w.hidden=eg||!e.canUndo,w.disabled=i,q.hidden=eh||ep||Y,V.hidden=eh||ep||Y;let X=ep?n.expand:n.minimize;F.title=X,F.setAttribute("aria-label",X),F.setAttribute("aria-expanded",String(!ep)),T.hidden=ep,D.hidden=!ep,q.disabled=i||""===u.value.trim()||eg&&""===R.value.trim(),u.disabled=i,ee.hidden=!e.features.includes("save")||P,ee.disabled=i||!e.unsaved,ee.textContent=e.saving?n.saving:n.save,et.hidden=!e.features.includes("publish")||P,et.disabled=i,et.textContent=e.publishing?n.publishing:n.publish,Q.hidden=!l||!1===r.signOut,p.hidden=!1===r.signOut,r.actions&&(r.actions.slot=ec&&o?"actions-footer":"actions-bar"),er.hidden=!l,G.hidden=!e.unsaved,W.hidden=!l,W.setAttribute("aria-expanded",String(ef)),H.textContent=ev?.find(({entryId:e})=>e===t.entryId)?.name??n.pages;let _=eh&&eb&&!ef,Z=e.prompting,K=e.prompting?eg?n.creating:Y?N.adding:n.working:_?"":eu?.text??(Y?N.hint:!l||eg||ef||e.selectedUid?"":n.selectHint);g.textContent=K,g.hidden=!K||ep,g.className=`status${Z?" working":""}${!i&&!_&&eu?.error?" error":""}`},eC=()=>eE(t.getState()),eP=()=>{u.style.height="auto",u.style.height=`${u.scrollHeight}px`},eA=()=>{eb=!0,m.classList.add("loading");let e=t.openForm(m,{title:n.formTitle,onReady:()=>{em===e&&(eb=!1,eu=null,eC())},onError:t=>{em===e&&(eb=!1,eu={text:t,error:!0},eC())}});em=e},eL=()=>{em?.close(),em=null,eb=!1},eS=e=>{eh!==e&&(eh=e,eu=null,eC(),eh||u.focus())},eN=async()=>{if(eh)return;let e=u.value.trim();if(e&&!t.getState().prompting){eu=null;try{if(eg){let r=R.value.trim();if(!r)return R.focus();await t.createPage(r,e),ev=null,ey=null,eu={text:n.created,error:!1}}else{let{summary:r}=await t.prompt(e);eu={text:r,error:!1}}u.value="",eP()}catch(e){eu=ek(e)}eC(),u.focus()}},eM=()=>(ey??(ey=t.pages().then(e=>{ev=e,ex=null,eU(),eC()},e=>{ey=null,ex=ek(e).text,eU()})),ey),eI=()=>{let e=Y.value.trim().toLowerCase();return(ev??[]).filter(t=>!e||t.name.toLowerCase().includes(e)||t.url.toLowerCase().includes(e)||`/${t.path}`.toLowerCase().includes(e))},eU=()=>{let r=eI();ew=Math.max(0,Math.min(ew,r.length-1)),X.textContent="",r.forEach((r,o)=>{let a=r.entryId===t.entryId,i=N(e,"li",{className:`option${o===ew?" active":""}`,id:`obelism-page-${o}`},N(e,"span",{className:"option-text"},N(e,"span",{textContent:r.name}),N(e,"span",{className:"option-path",textContent:r.url})));if(i.setAttribute("role","option"),i.setAttribute("aria-selected",String(o===ew)),"published"!==r.status&&i.appendChild(N(e,"span",{className:"badge",textContent:"draft"===r.status?n.pageDraft:n.pageChanged})),a){i.setAttribute("aria-current","page");let t=M(e,"check");t.removeAttribute("aria-hidden"),t.setAttribute("role","img"),t.setAttribute("aria-label",n.pageCurrent),i.appendChild(t)}i.addEventListener("click",()=>eO(r)),X.appendChild(i)});let o=X.children[ew];o?(Y.setAttribute("aria-activedescendant",o.id),o.scrollIntoView?.({block:"nearest"})):Y.removeAttribute("aria-activedescendant"),_.textContent=(ex??(ev?"":n.pagesLoading))||(0===r.length?n.pagesEmpty:""),_.hidden=!_.textContent,_.className=`empty${ex?" error":""}`},e$=e=>{eu=null,(ef=e)&&(Y.value="",ew=Math.max(0,(ev??[]).findIndex(({entryId:e})=>e===t.entryId)),eM(),eU()),eC(),(ef?Y:W).focus()},eO=e=>{if(e.entryId===t.entryId)return e$(!1);t.openPage(e)},eR=e=>{(ec=e)||(ef=!1,ep=!1),eC(),l&&t.setSelecting(ec&&!eg),ec&&l&&eM()},ej=e=>{eg=e,eu=null,t.setSelecting(ec&&!eg),eg&&t.select(null),eC(),(eg?R:u).focus()},ez=async e=>{eu=null;try{await t[e](),eu={text:"save"===e?n.saved:n.published,error:!1}}catch(e){eu=ek(e)}eC()};d.addEventListener("click",()=>{eR(!0),eh||(eg?R:u).focus()}),z.addEventListener("click",()=>eR(!1)),F.addEventListener("click",()=>{ep=!ep,eC(),ep||(eh?F:u).focus()}),eo.addEventListener("click",e=>{if(!ep)return;let t=e.target.closest("button");t&&t!==F&&t!==z&&(ep=!1,eC())},!0),ee.addEventListener("click",()=>void ez("save")),et.addEventListener("click",()=>void ez("publish")),Q.addEventListener("click",()=>t.signOut()),p.addEventListener("click",()=>t.signOut()),y.addEventListener("click",()=>t.select(null)),I.addEventListener("click",()=>ej(!0)),U.addEventListener("click",async()=>{eu=null;try{t.product?(await t.createProductPage(),eu={text:n.addedProductPage,error:!1}):(await t.createCollectionPage(),eu={text:n.addedCollectionPage,error:!1})}catch(e){eu=ek(e)}eC()}),$.addEventListener("click",()=>ej(!1)),E.addEventListener("click",()=>eS(!1)),C.addEventListener("click",()=>eS(!0)),W.addEventListener("click",()=>e$(!ef)),R.addEventListener("input",eC),R.addEventListener("keydown",e=>{"Enter"!==e.key||e.isComposing?"Escape"===e.key&&eR(!1):(e.preventDefault(),u.focus())}),Y.addEventListener("input",()=>{ew=0,eU()}),Y.addEventListener("keydown",e=>{let t=X.children.length;if("ArrowDown"===e.key||"ArrowUp"===e.key){if(e.preventDefault(),0===t)return;ew=(ew+("ArrowDown"===e.key?1:-1)+t)%t,eU()}else if("Enter"!==e.key||e.isComposing)"Escape"===e.key&&(e.preventDefault(),e$(!1));else{e.preventDefault();let t=eI()[ew];t&&eO(t)}}),w.addEventListener("click",()=>{eu=null,t.undo()}),eo.addEventListener("submit",e=>{e.preventDefault(),eN()}),u.addEventListener("input",()=>{eP(),eC()}),u.addEventListener("keydown",e=>{"Enter"!==e.key||e.shiftKey||e.isComposing?"Escape"===e.key&&eR(!1):(e.preventDefault(),eN())});let eT=t.on("change",eE);return eC(),e.body.appendChild(a),()=>{eT(),eL(),a.remove()}},U="https://content.obelism.studio",$=(e,t)=>JSON.stringify(e)===JSON.stringify(t),O=Symbol.for("@obelism/content/bridge"),R=C({isEditing:!1,entryId:null,on:()=>{}},new URLSearchParams),j=({url:e,prompt:c=!0,pagePath:p,productPath:m,collectionPath:y}={})=>{let x;if("u"<typeof window)return R;let P=window;if(P[O])return P[O];if(P.ObelismBridge)x=C(P.ObelismBridge,new URLSearchParams(P.location.search));else{let C=(x=((e,r)=>{let o,n,c,p,m,y=new URLSearchParams(e.location.search),x=e.parent!==e&&y.has("cms_preview"),C=v(),P=[],A={...f,selecting:!0},L=e=>{A={...A,...e},C.emit("change",A)},S={isEditing:x,mode:x?"editor":null,entryId:y.get("cms_entry"),environment:y.get(a),product:null,collection:null,on:C.on,getState:()=>A,...w,destroy:()=>{P.splice(0).forEach(e=>e())}};if(!x)return S;let N=e.document,M=(t,o={})=>{e.parent.postMessage({source:h,type:t,...o},r)},I=N.createElement("style");I.textContent=b(),N.head.appendChild(I),P.push(()=>I.remove());let U=(e,t)=>{if(N.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),A.selectedUid!==(e??null)&&L({selectedUid:e??null}),!e)return;let r=N.querySelector(E(e));r&&(r.setAttribute("data-cms-selected",""),t&&r.scrollIntoView({behavior:"smooth",block:"center"}))},$=e=>{let r=e.target,o=r?.closest?.(`[${t}]`);if(!o)return;e.preventDefault(),e.stopPropagation();let n=o.getAttribute(t);U(n,!1),M("select",{uid:n})};N.addEventListener("click",$,!0),P.push(()=>N.removeEventListener("click",$,!0));let O=()=>Math.ceil(Math.max(N.documentElement.scrollHeight,N.body?.scrollHeight??0)),R=0,j=()=>{R=O(),M("ready",{url:e.location.href,height:R})},z=e.ResizeObserver;if("function"==typeof z){let e=new z(()=>{let e=O();e!==R&&(R=e,M("size",{height:e}))});e.observe(N.documentElement),N.body&&e.observe(N.body),P.push(()=>e.disconnect())}let T=new Map,D=0,F=e=>{let t=T.get(e);return t?(clearTimeout(t.timer),T.delete(e),0===T.size&&L({prompting:!1}),t):null};S.prompt=(e,t={})=>{let r=e.trim();if(!r)return Promise.reject(Error("Say what to change"));if(!A.features.includes("prompt"))return Promise.reject(Error("The editor does not offer prompts here"));let o=`prompt_${++D}`,n=void 0===t.uid?A.selectedUid:t.uid;return new Promise((e,t)=>{let a=setTimeout(()=>{F(o)?.reject(Error("The editor did not answer in time"))},12e4);T.set(o,{resolve:e,reject:t,timer:a}),L({prompting:!0}),M("prompt",{id:o,prompt:r,uid:n})})},S.undo=()=>M("undo"),S.select=e=>{U(e,!1),M("select",{uid:e})};let q=null;P.push(()=>q?.destroy()),P.push(()=>{for(let e of T.keys())F(e)?.reject(Error("The bridge was destroyed"))});let V=(o=new WeakSet,n=null,c=null,p=!1,m=()=>{if(null!==n){for(let e of Array.from(N.styleSheets)){let t;if(!o.has(e)){try{t=e.cssRules}catch{continue}o.add(e),u(t,n)}}N.querySelectorAll('[style*="vh"]').forEach(e=>{g(e.style,n)})}},{freeze(e){if(null!==n||!(e>0))return;n=e,m();let t=N.defaultView?.MutationObserver;t&&(c=new t(()=>{if(p)return;p=!0;let e=()=>{p=!1,m()};N.defaultView?.requestAnimationFrame?N.defaultView.requestAnimationFrame(e):e()})).observe(N.documentElement,{childList:!0,subtree:!0})},destroy(){c?.disconnect()}});P.push(()=>V.destroy());let B=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)j();else if("update"===o.type&&o.entry)C.emit("update",{entry:o.entry,selectedUid:o.selectedUid??null}),e.requestAnimationFrame(()=>U(o.selectedUid,!1)),q?.refresh();else if("select"===o.type)U(o.uid,!0);else if("saved"===o.type||"published"===o.type)C.emit(o.type,{}),0===C.listeners.update.size&&e.location.reload();else if("features"===o.type&&Array.isArray(o.features))L({features:o.features.filter(e=>"string"==typeof e)});else if("stats"===o.type)L({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??{};k(e)&&k(n)&&k(a)&&k(i)&&(t[r]={clicks:e,clickers:n,viewers:a,rate:i})}return t})(o.stats),statsVisible:!1!==o.visible}),(q||Object.keys(A.stats).length)&&(q??(q=((e,{selector:t,onSelect:r,labels:o})=>{let n=e.document,a={...i,...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={},m=!1,b=null,f=()=>{if(b=null,u.replaceChildren(),u.hidden=!m,!m)return;let o=e.innerHeight;for(let[i,s]of Object.entries(h)){let c=n.querySelector(t(i));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=i,g.textContent=l(a.clicked,{rate:Math.round(100*s.rate)}),g.title=l(a.title,{clickers:s.clickers,viewers:s.viewers,clicks:s.clicks});let{place:h,top:m,left:b}=d(p,e.innerWidth);g.dataset.place=h,g.style.top=`${m}px`,g.style.left=`${b}px`,g.addEventListener("click",()=>r(i)),u.appendChild(g)}},v=()=>{null===b&&m&&(b=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,m=r,null!==b&&(e.cancelAnimationFrame?.(b),b=null),f()},refresh:v,destroy(){null!==b&&e.cancelAnimationFrame?.(b),e.removeEventListener("scroll",v,{capture:!0}),e.removeEventListener("resize",v),x?.disconnect(),c.remove()}}})(e,{selector:E,onSelect:e=>S.select(e)})),q.update(A.stats,A.statsVisible));else if("viewport"===o.type&&"number"==typeof o.height)V.freeze(o.height);else if("promptState"===o.type)L({canUndo:!0===o.canUndo});else if("promptResult"===o.type&&"string"==typeof o.id){let e=F(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),P.push(()=>e.removeEventListener("message",B)),"loading"===N.readyState?(N.addEventListener("DOMContentLoaded",j,{once:!0}),P.push(()=>N.removeEventListener("DOMContentLoaded",j))):j(),S})(P,new URL(e||U).origin)).isEditing||P.parent!==P?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})(P.document);if(C&&(x=((e,a,{pagePath:i=e=>`/${e}`,productPath:l,collectionPath:s}={})=>{let d=e.document,c=v(),p=[],g=new Map,u=[],m=new Set,y=null,x=null,w=-1/0,k=new Map,C=f,P=e=>{C={...C,...e},c.emit("change",C)},A=()=>P({unsaved:[...g.values()].some(({content:e,saved:t})=>!$(e,t)),canUndo:u.length>0}),L=async(t,r)=>{let o=await e.fetch(`${a}/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)}),n=await o.json().catch(()=>({}));if(401===o.status)throw P({features:[]}),Error("You were signed out. Sign in again to edit.");if(!o.ok)throw Error("string"==typeof n.error?n.error:`Obelism Content answered ${o.status}`);return n},S=()=>d.querySelector(`[${r}]`)?.getAttribute(r)??null,N=()=>{let e=d.querySelector(`[${o}]`),t=e?.getAttribute(o),r=e?.getAttribute("data-cms-product-handle");return t&&r?{id:t,handle:r}:null},M=()=>{let e=d.querySelector(`[${n}]`),t=e?.getAttribute(n),r=e?.getAttribute("data-cms-collection-handle");return t&&r?{id:t,handle:r}:null},I=e=>{let t=e?d.querySelector(E(e)):null;return t?.closest(`[${r}]`)?.getAttribute(r)??S()},U=()=>{if(!y)return;let e=y.space.locales.map(({code:e})=>e),t=d.documentElement.lang;if(e.includes(t))return t;let r=t.split("-")[0]??"";return e.includes(r)?r:y.space.defaultLocale},O=new Map,R=async e=>{let t=g.get(e);if(t)return t;let r=O.get(e);return r||(r=L(`entries/${encodeURIComponent(e)}`).then(t=>{let r=g.get(e)??{content:t.content,saved:t.content,revision:t.draftRevision};return g.set(e,r),r}).finally(()=>O.delete(e)),O.set(e,r)),r},j=e=>{let t=void 0===e?C.selectedUid:e,r=I(t);if(!r)throw Error("Nothing on this page is marked as an entry: add editable(entry)");return{uid:t,entryId:r}},z=e=>{d.querySelectorAll("[data-cms-selected]").forEach(e=>{e.removeAttribute("data-cms-selected")}),C.selectedUid!==e&&P({selectedUid:e}),e&&d.querySelector(E(e))?.setAttribute("data-cms-selected","")},T=async t=>{if(0===c.listeners.update.size)return;let r=g.get(t)?.content,{entry:o}=await L(`entries/${encodeURIComponent(t)}/preview`,{content:r,locale:U()});c.emit("update",{entry:o,selectedUid:C.selectedUid}),e.requestAnimationFrame(()=>z(C.selectedUid))},D=e=>console.error("[@obelism/content bridge]",e),F=t=>{c.emit(t,{}),0===c.listeners.update.size&&e.location.reload()},q=async()=>{for(let[e,t]of g){if($(t.content,t.saved))continue;let{draftRevision:r}=await L(`entries/${encodeURIComponent(e)}/save`,{content:t.content,baseRevision:t.revision});t.saved=t.content,t.revision=r,m.add(e)}u.length=0,w=-1/0,A()},V={isEditing:!0,mode:"site",get entryId(){return S()},get product(){return N()},get collection(){return M()},environment:null,on:c.on,getState:()=>C,async prompt(e,t={}){let r=e.trim();if(!r)throw Error("Say what to change");if(!C.features.includes("prompt"))throw Error("You may not edit content here");let{uid:o,entryId:n}=j(t.uid);P({prompting:!0});try{let e=await R(n),t=await L(`entries/${encodeURIComponent(n)}/prompt`,{prompt:r,content:e.content,locale:U(),uid:o});return u.push({entryId:n,content:e.content}),w=-1/0,e.content=t.content,A(),await T(n),{summary:t.summary}}finally{P({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(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("entries",{path:t,prompt:o,locale:U(),from:S()}),n=i(r.path,U()??"");return e.location.assign(n),{summary:r.summary,entryId:r.entryId,path:r.path,url:n}}finally{P({prompting:!1})}},async createProductPage(t=N()??void 0){if(!t)throw Error("Nothing on this page is marked as a product: add editableProduct(product)");if(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("product-pages",{product:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{P({prompting:!1})}},async createCollectionPage(t=M()??void 0){if(!t)throw Error("Nothing on this page is marked as a collection: add editableCollection(collection)");if(!C.features.includes("create"))throw Error("You may not add pages here");if(C.unsaved)throw Error("Save or undo your changes before adding a page");P({prompting:!0});try{let r=await L("collection-pages",{collection:{id:t.id,handle:t.handle}});return e.location.reload(),r}finally{P({prompting:!1})}},async view(e={}){let{uid:t,entryId:r}=j(e.uid),o=await R(r),{view:n}=await L(`entries/${encodeURIComponent(r)}/view`,{content:o.content,locale:U(),uid:t});return n},async applyJson(e,t={}){if(!C.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}=j(t.uid);P({prompting:!0});try{let t=await R(o),n=await L(`entries/${encodeURIComponent(o)}/apply`,{changes:e,content:t.content,locale:U(),uid:r});return $(n.content,t.content)||(u.push({entryId:o,content:t.content}),w=-1/0,t.content=n.content,A(),await T(o)),{changed:n.changed??[],...n.view&&{view:n.view}}}finally{P({prompting:!1})}},openForm(t,r={}){let{title:o="Content form",onReady:n,onError:a}=r;x?.();let i=!1,l=null,s=null,d=()=>{},p=e=>{i||a?.(e instanceof Error?e.message:String(e))},m=()=>{i||(i=!0,d(),l?.destroy(),x===m&&(x=null))};x=m;let b=()=>{if(i||!l)return;let e=I(C.selectedUid);if(!e)return;let t=g.get(e);if(!t)return void R(e).then(b,p);let r={entryId:e,content:t.content,locale:U(),selectedUid:C.selectedUid};s&&s.entryId===r.entryId&&s.content===r.content&&s.locale===r.locale&&s.selectedUid===r.selectedUid||(s=r,l.show(r))},f=(e,t)=>{let r=t??s?.entryId,o=void 0===r?void 0:g.get(r);if(i||void 0===r||!o||$(e,o.content))return;let n=Date.now();n-w>=1e3&&u.push({entryId:r,content:o.content}),w=n,o.content=e,s?.entryId===r&&(s={...s,content:e}),A(),clearTimeout(k.get(r)),k.set(r,setTimeout(()=>{k.delete(r),T(r).catch(D)},300))};return(async()=>{if(!C.features.includes("form"))throw Error("You may not edit content here");await R(j(void 0).entryId);let{url:r}=await L("form",{});i||(l=((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,l=t.ownerDocument.createElement("iframe");l.title=o,l.src=r;let s=!1,d=!1,c=null,p=()=>{s&&c&&l.contentWindow?.postMessage({source:h,type:"content",...c},i)},g=setTimeout(()=>{d||n.onError("The form did not open")},3e4),u=()=>{d=!0,clearTimeout(g),n.onReady()},m=e=>{if(e.origin!==i||!l.contentWindow||e.source!==l.contentWindow)return;let t=e.data;if(t&&"obelism-content-form"===t.source)if("ready"===t.type)s=!0,p(),!0!==t.loading&&u();else if("loaded"===t.type)s&&u();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));l.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",m),t.appendChild(l),{show(e){c=e,p()},destroy(){clearTimeout(g),e.removeEventListener("message",m),l.remove()}}})(e,t,"string"==typeof r?r:"",o,{onReady:()=>n?.(),onChange:f,onError:e=>a?.(e)}),d=c.on("change",b),b())})().catch(p),{close:m}},async pages(){let{pages:e}=await L("pages"),t=[U(),y?.space.defaultLocale];return e.flatMap(e=>{let r,o,n=t.find(t=>void 0!==t&&void 0!==e.paths[t])??Object.keys(e.paths)[0],a=void 0===n?void 0:e.paths[n];return void 0===n||void 0===a?[]:[{entryId:e.entryId,name:e.name,contentType:e.contentType,status:e.status,path:a,url:e.product?(r=e.product.handle,l?l(r,n):(y?.productPath??"/products/{handle}").replaceAll("{handle}",encodeURIComponent(r))):e.collection?(o=e.collection.handle,s?s(o,n):(y?.collectionPath??"/collections/{handle}").replaceAll("{handle}",encodeURIComponent(o))):i(a,n),product:e.product??null,collection:e.collection??null}]})},openPage(t){(!C.unsaved||e.confirm("Leave this page and lose the changes you have not saved?"))&&(g.clear(),u.length=0,A(),e.location.assign(t.url))},undo(){let e=u.pop(),t=e&&g.get(e.entryId);e&&t&&(w=-1/0,t.content=e.content,A(),T(e.entryId).catch(D))},async save(){if(!C.features.includes("save"))throw Error("You may not edit content here");P({saving:!0});try{await q()}finally{P({saving:!1})}F("saved")},async publish(){if(!C.features.includes("publish"))throw Error("You may not publish here");P({publishing:!0});try{await q();let e=S(),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 L(`entries/${encodeURIComponent(e)}/publish`,{}),m.delete(e)}finally{P({publishing:!1})}F("published")},signOut(){if(C.unsaved&&!e.confirm("Sign out and lose the changes you have not saved?"))return;g.clear(),A();let t=e.location.pathname+e.location.search;e.location.href=`${a}/logout?return_to=${encodeURIComponent(t)}`},select(e){z(e)},setSelecting(e){e?d.documentElement.setAttribute("data-cms-selecting",""):d.documentElement.removeAttribute("data-cms-selecting"),P({selecting:e})},destroy(){x?.(),k.forEach(e=>clearTimeout(e)),k.clear(),p.splice(0).forEach(e=>e())}},B=d.createElement("style");B.textContent=b("html[data-cms-selecting] "),d.head.appendChild(B),p.push(()=>B.remove()),p.push(()=>d.documentElement.removeAttribute("data-cms-selecting"));let H=e=>{if(!C.selecting)return;let r=e.target,o=r?.closest?.(`[${t}]`);o&&(e.preventDefault(),e.stopPropagation(),z(o.getAttribute(t)))};d.addEventListener("click",H,!0),p.push(()=>d.removeEventListener("click",H,!0));let W=e=>{C.unsaved&&(e.preventDefault(),e.returnValue="")};return e.addEventListener("beforeunload",W),p.push(()=>e.removeEventListener("beforeunload",W)),L("session").then(e=>{y=e,P({features:e.features})}).catch(e=>console.error("[@obelism/content bridge]",e)),V})(P,C,{pagePath:p,productPath:m,collectionPath:y})),x.isEditing&&c){let e=P.document,t=()=>{},r=!1,o=()=>{r||(t=I(e,x,!0===c?{}:c))};e.body?o():e.addEventListener("DOMContentLoaded",o,{once:!0});let n=x.destroy;x.destroy=()=>{r=!0,e.removeEventListener("DOMContentLoaded",o),t(),n()}}}return P[O]=x,x};(e=window).ObelismBridge=j((e=>{let t=e?.dataset.url,r=t||U;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:j,mountPromptBox:I}}();
|
package/dist/bridge.js
CHANGED
|
@@ -626,6 +626,7 @@ const DEFAULT_PROMPT_LABELS = {
|
|
|
626
626
|
minimize: 'Minimize, to see the page',
|
|
627
627
|
expand: 'Expand',
|
|
628
628
|
scopeEntry: 'Whole page',
|
|
629
|
+
scopeNoPage: 'Whole page',
|
|
629
630
|
scopeBlock: 'Selected block',
|
|
630
631
|
clearBlock: 'Edit the whole page instead',
|
|
631
632
|
working: 'Working on it…',
|
|
@@ -755,7 +756,7 @@ button:disabled { cursor: not-allowed; }
|
|
|
755
756
|
button:focus-visible { outline: 2px solid rgb(var(--theme-accent-rgb)); outline-offset: 2px; }
|
|
756
757
|
|
|
757
758
|
/* Closed: one floating pill that reads like an empty field, with the mark. */
|
|
758
|
-
.bar { display: flex; justify-content: center; }
|
|
759
|
+
.bar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
|
|
759
760
|
.pill {
|
|
760
761
|
display: flex; align-items: center; gap: 12px; width: min(560px, 100%); height: 56px;
|
|
761
762
|
padding: 0 22px 0 26px; border-radius: var(--border-radius-pill);
|
|
@@ -886,7 +887,7 @@ button.chip:disabled { opacity: .5; }
|
|
|
886
887
|
|
|
887
888
|
/* On the site: storing the draft, and the way out. */
|
|
888
889
|
.footer {
|
|
889
|
-
display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
890
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
890
891
|
border-top: 1px solid rgb(var(--theme-border-rgb) / .2);
|
|
891
892
|
background: rgb(var(--theme-background-actions-rgb) / .45);
|
|
892
893
|
}
|
|
@@ -1141,6 +1142,16 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1141
1142
|
}, element(doc, 'label', {
|
|
1142
1143
|
className: 'search'
|
|
1143
1144
|
}, icon(doc, 'search'), search), optionList, pagesNote);
|
|
1145
|
+
// The page's own controls (`actions`), in the footer while open and next
|
|
1146
|
+
// to the pill while closed.
|
|
1147
|
+
const actionsInFooter = element(doc, 'slot');
|
|
1148
|
+
actionsInFooter.name = 'actions-footer';
|
|
1149
|
+
const actionsInBar = element(doc, 'slot');
|
|
1150
|
+
actionsInBar.name = 'actions-bar';
|
|
1151
|
+
if (options.actions) {
|
|
1152
|
+
options.actions.slot = 'actions-bar';
|
|
1153
|
+
host.appendChild(options.actions);
|
|
1154
|
+
}
|
|
1144
1155
|
const unsaved = element(doc, 'span', {
|
|
1145
1156
|
className: 'unsaved'
|
|
1146
1157
|
});
|
|
@@ -1167,7 +1178,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1167
1178
|
className: 'footer'
|
|
1168
1179
|
}, pageChip, unsaved, element(doc, 'span', {
|
|
1169
1180
|
className: 'spacer'
|
|
1170
|
-
}), signOut, save, publish);
|
|
1181
|
+
}), actionsInFooter, signOut, save, publish);
|
|
1171
1182
|
const panel = element(doc, 'form', {
|
|
1172
1183
|
className: 'panel'
|
|
1173
1184
|
}, status, pathRow, input, formBox, toolbar, pagesSection, footer);
|
|
@@ -1175,7 +1186,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1175
1186
|
className: 'root'
|
|
1176
1187
|
}, element(doc, 'div', {
|
|
1177
1188
|
className: 'bar'
|
|
1178
|
-
}, pill, viewing), panel);
|
|
1189
|
+
}, pill, viewing, actionsInBar), panel);
|
|
1179
1190
|
shadow.append(element(doc, 'style', {
|
|
1180
1191
|
textContent: CSS
|
|
1181
1192
|
}), root);
|
|
@@ -1204,7 +1215,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1204
1215
|
dragged = false;
|
|
1205
1216
|
if (event.button !== 0 || !event.isPrimary) return;
|
|
1206
1217
|
const target = event.target;
|
|
1207
|
-
const control = target.closest('button, input, textarea, iframe, a, label, .pages, .form');
|
|
1218
|
+
const control = target.closest('button, input, textarea, select, iframe, a, label, .pages, .form');
|
|
1208
1219
|
if (control && control !== pill) return;
|
|
1209
1220
|
const { left, right } = root.getBoundingClientRect();
|
|
1210
1221
|
drag = {
|
|
@@ -1341,7 +1352,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1341
1352
|
toolbar.hidden = picking;
|
|
1342
1353
|
pagesSection.hidden = !picking;
|
|
1343
1354
|
input.placeholder = creating ? labels.newPagePlaceholder : labels.placeholder;
|
|
1344
|
-
scopeText.textContent = state.selectedUid ? labels.scopeBlock : labels.scopeEntry;
|
|
1355
|
+
scopeText.textContent = state.selectedUid ? labels.scopeBlock : pageless ? labels.scopeNoPage : labels.scopeEntry;
|
|
1345
1356
|
clearBlock.hidden = !state.selectedUid;
|
|
1346
1357
|
pageIcon.hidden = !!state.selectedUid;
|
|
1347
1358
|
blockIcon.hidden = !state.selectedUid;
|
|
@@ -1371,7 +1382,11 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1371
1382
|
publish.hidden = !state.features.includes('publish') || pageless;
|
|
1372
1383
|
publish.disabled = busy;
|
|
1373
1384
|
publish.textContent = state.publishing ? labels.publishing : labels.publish;
|
|
1374
|
-
signOut.hidden = !site;
|
|
1385
|
+
signOut.hidden = !site || options.signOut === false;
|
|
1386
|
+
pillSignOut.hidden = options.signOut === false;
|
|
1387
|
+
if (options.actions) {
|
|
1388
|
+
options.actions.slot = open && available ? 'actions-footer' : 'actions-bar';
|
|
1389
|
+
}
|
|
1375
1390
|
footer.hidden = !site;
|
|
1376
1391
|
unsaved.hidden = !state.unsaved;
|
|
1377
1392
|
pageChip.hidden = !site;
|
package/dist/bridge.mjs
CHANGED
|
@@ -624,6 +624,7 @@ const DEFAULT_PROMPT_LABELS = {
|
|
|
624
624
|
minimize: 'Minimize, to see the page',
|
|
625
625
|
expand: 'Expand',
|
|
626
626
|
scopeEntry: 'Whole page',
|
|
627
|
+
scopeNoPage: 'Whole page',
|
|
627
628
|
scopeBlock: 'Selected block',
|
|
628
629
|
clearBlock: 'Edit the whole page instead',
|
|
629
630
|
working: 'Working on it…',
|
|
@@ -753,7 +754,7 @@ button:disabled { cursor: not-allowed; }
|
|
|
753
754
|
button:focus-visible { outline: 2px solid rgb(var(--theme-accent-rgb)); outline-offset: 2px; }
|
|
754
755
|
|
|
755
756
|
/* Closed: one floating pill that reads like an empty field, with the mark. */
|
|
756
|
-
.bar { display: flex; justify-content: center; }
|
|
757
|
+
.bar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
|
|
757
758
|
.pill {
|
|
758
759
|
display: flex; align-items: center; gap: 12px; width: min(560px, 100%); height: 56px;
|
|
759
760
|
padding: 0 22px 0 26px; border-radius: var(--border-radius-pill);
|
|
@@ -884,7 +885,7 @@ button.chip:disabled { opacity: .5; }
|
|
|
884
885
|
|
|
885
886
|
/* On the site: storing the draft, and the way out. */
|
|
886
887
|
.footer {
|
|
887
|
-
display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
888
|
+
display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px 10px 22px;
|
|
888
889
|
border-top: 1px solid rgb(var(--theme-border-rgb) / .2);
|
|
889
890
|
background: rgb(var(--theme-background-actions-rgb) / .45);
|
|
890
891
|
}
|
|
@@ -1139,6 +1140,16 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1139
1140
|
}, element(doc, 'label', {
|
|
1140
1141
|
className: 'search'
|
|
1141
1142
|
}, icon(doc, 'search'), search), optionList, pagesNote);
|
|
1143
|
+
// The page's own controls (`actions`), in the footer while open and next
|
|
1144
|
+
// to the pill while closed.
|
|
1145
|
+
const actionsInFooter = element(doc, 'slot');
|
|
1146
|
+
actionsInFooter.name = 'actions-footer';
|
|
1147
|
+
const actionsInBar = element(doc, 'slot');
|
|
1148
|
+
actionsInBar.name = 'actions-bar';
|
|
1149
|
+
if (options.actions) {
|
|
1150
|
+
options.actions.slot = 'actions-bar';
|
|
1151
|
+
host.appendChild(options.actions);
|
|
1152
|
+
}
|
|
1142
1153
|
const unsaved = element(doc, 'span', {
|
|
1143
1154
|
className: 'unsaved'
|
|
1144
1155
|
});
|
|
@@ -1165,7 +1176,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1165
1176
|
className: 'footer'
|
|
1166
1177
|
}, pageChip, unsaved, element(doc, 'span', {
|
|
1167
1178
|
className: 'spacer'
|
|
1168
|
-
}), signOut, save, publish);
|
|
1179
|
+
}), actionsInFooter, signOut, save, publish);
|
|
1169
1180
|
const panel = element(doc, 'form', {
|
|
1170
1181
|
className: 'panel'
|
|
1171
1182
|
}, status, pathRow, input, formBox, toolbar, pagesSection, footer);
|
|
@@ -1173,7 +1184,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1173
1184
|
className: 'root'
|
|
1174
1185
|
}, element(doc, 'div', {
|
|
1175
1186
|
className: 'bar'
|
|
1176
|
-
}, pill, viewing), panel);
|
|
1187
|
+
}, pill, viewing, actionsInBar), panel);
|
|
1177
1188
|
shadow.append(element(doc, 'style', {
|
|
1178
1189
|
textContent: CSS
|
|
1179
1190
|
}), root);
|
|
@@ -1202,7 +1213,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1202
1213
|
dragged = false;
|
|
1203
1214
|
if (event.button !== 0 || !event.isPrimary) return;
|
|
1204
1215
|
const target = event.target;
|
|
1205
|
-
const control = target.closest('button, input, textarea, iframe, a, label, .pages, .form');
|
|
1216
|
+
const control = target.closest('button, input, textarea, select, iframe, a, label, .pages, .form');
|
|
1206
1217
|
if (control && control !== pill) return;
|
|
1207
1218
|
const { left, right } = root.getBoundingClientRect();
|
|
1208
1219
|
drag = {
|
|
@@ -1339,7 +1350,7 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1339
1350
|
toolbar.hidden = picking;
|
|
1340
1351
|
pagesSection.hidden = !picking;
|
|
1341
1352
|
input.placeholder = creating ? labels.newPagePlaceholder : labels.placeholder;
|
|
1342
|
-
scopeText.textContent = state.selectedUid ? labels.scopeBlock : labels.scopeEntry;
|
|
1353
|
+
scopeText.textContent = state.selectedUid ? labels.scopeBlock : pageless ? labels.scopeNoPage : labels.scopeEntry;
|
|
1343
1354
|
clearBlock.hidden = !state.selectedUid;
|
|
1344
1355
|
pageIcon.hidden = !!state.selectedUid;
|
|
1345
1356
|
blockIcon.hidden = !state.selectedUid;
|
|
@@ -1369,7 +1380,11 @@ const mountPromptBox = (doc, bridge, options = {})=>{
|
|
|
1369
1380
|
publish.hidden = !state.features.includes('publish') || pageless;
|
|
1370
1381
|
publish.disabled = busy;
|
|
1371
1382
|
publish.textContent = state.publishing ? labels.publishing : labels.publish;
|
|
1372
|
-
signOut.hidden = !site;
|
|
1383
|
+
signOut.hidden = !site || options.signOut === false;
|
|
1384
|
+
pillSignOut.hidden = options.signOut === false;
|
|
1385
|
+
if (options.actions) {
|
|
1386
|
+
options.actions.slot = open && available ? 'actions-footer' : 'actions-bar';
|
|
1387
|
+
}
|
|
1373
1388
|
footer.hidden = !site;
|
|
1374
1389
|
unsaved.hidden = !state.unsaved;
|
|
1375
1390
|
pageChip.hidden = !site;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obelism/content",
|
|
3
3
|
"description": "Obelism Content SDK: the delivery API client, the visual editor bridge with prompt editing, editing on your own site, webhook verification, and the content model CLI",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
7
7
|
"headless-cms",
|