@viglet/shio-editor-cors 2026.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @viglet/shio-editor-cors
2
+
3
+ [![npm](https://img.shields.io/npm/v/@viglet/shio-editor-cors?logo=npm)](https://www.npmjs.com/package/@viglet/shio-editor-cors)
4
+ [![License](https://img.shields.io/npm/l/@viglet/shio-editor-cors)](https://github.com/openviglet/shio/blob/HEAD/LICENSE)
5
+ [![Website](https://img.shields.io/badge/shio.viglet.org-0ea5e9?logo=googlechrome&logoColor=white)](https://shio.viglet.org/)
6
+
7
+ The **Universal Editor bridge** for **[Viglet Shio](https://shio.viglet.org/)**,
8
+ the open source **headless CMS built for coding agents**. Drop it into *any*
9
+ front end — Next.js, Astro, Nuxt, Remix, plain HTML — and the page becomes
10
+ **inline-editable** inside the Shio console, across origins.
11
+
12
+ Zero dependencies, ~one file, no framework assumptions. It annotates nothing on
13
+ its own: **you** mark what is editable with `data-sh-*` attributes, and this
14
+ bridge turns those marks into click-to-edit regions, talks to the console shell
15
+ over `postMessage`, and reports the changes back.
16
+
17
+ > Shio's own renderer injects an equivalent bridge automatically. **This package
18
+ > is for front ends that render themselves** and emit their own `data-sh-*`
19
+ > attributes — one bridge per producer.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @viglet/shio-editor-cors
25
+ ```
26
+
27
+ ```ts
28
+ // Import once, as high in the app as you can. It self-initializes on DOM ready.
29
+ import "@viglet/shio-editor-cors";
30
+ ```
31
+
32
+ Or as a plain script tag (IIFE build):
33
+
34
+ ```html
35
+ <script src="https://unpkg.com/@viglet/shio-editor-cors/dist/shio-editor-cors.iife.js"></script>
36
+ ```
37
+
38
+ ## Configure with meta tags
39
+
40
+ The bridge reads its configuration from the document head, so it works the same
41
+ whether it was bundled or dropped in as a tag:
42
+
43
+ ```html
44
+ <!-- Which console origin is allowed to edit this page. REQUIRED —
45
+ without it the bridge stays inert and logs why. -->
46
+ <meta name="urn:shio:system:editor-origin" content="https://cms.example.com">
47
+
48
+ <!-- Which Shio instance the content lives in. -->
49
+ <meta name="urn:shio:system:connection" content="shio:https://cms.example.com">
50
+
51
+ <!-- Optional context, sent to the console on `sh:ready`. -->
52
+ <meta name="urn:shio:system:site" content="acme">
53
+ <meta name="urn:shio:system:path" content="/blog">
54
+ ```
55
+
56
+ The editor origin has to be *told*: a framed page cannot work out who framed it —
57
+ `document.referrer` is empty on some navigations and `window.parent.location`
58
+ throws cross-origin — so a missing tag is a loud `console.warn`, never a silent
59
+ no-op.
60
+
61
+ ## Mark what is editable
62
+
63
+ | Attribute | Meaning |
64
+ |---|---|
65
+ | `data-sh-resource` | The Shio address this subtree maps to (e.g. `post:acme/blog/hello`) — the editable root |
66
+ | `data-sh-prop` | Which attribute of that post this element renders |
67
+ | `data-sh-type` | `text` (default), `richtext`, `container`, `component` |
68
+ | `data-sh-label` | The label shown on hover in edit mode |
69
+ | `data-sh-model` | The post-type name, when it is not inherited from the resource root |
70
+
71
+ ```html
72
+ <article data-sh-resource="post:acme/blog/hello" data-sh-model="Article">
73
+ <h1 data-sh-prop="title" data-sh-type="text" data-sh-label="Title">
74
+ Hello world
75
+ </h1>
76
+ <div data-sh-prop="content" data-sh-type="richtext" data-sh-label="Body">
77
+ <p>…</p>
78
+ </div>
79
+ </article>
80
+ ```
81
+
82
+ `data-sh-prop` elements nested under a `data-sh-resource` inherit the resource
83
+ and the model, so you only annotate the root once.
84
+
85
+ ## How it works
86
+
87
+ 1. On DOM ready the bridge reads the meta tags. No editor origin → inert.
88
+ 2. It injects the edit-mode styles and posts `sh:ready` to the parent frame with
89
+ the page URL, title, editable count and connection details.
90
+ 3. The Shio console shell toggles `preview` / `edit` mode over `postMessage`.
91
+ 4. In edit mode a click on an annotated element opens an inline text or rich-text
92
+ editor; changes are collected and sent back to the console to be saved.
93
+
94
+ Every message is origin-checked against the configured editor origin.
95
+
96
+ ## Related packages
97
+
98
+ | Package | For |
99
+ |---|---|
100
+ | [`@viglet/shio-client`](https://www.npmjs.com/package/@viglet/shio-client) | Zero-dependency Content Delivery API client |
101
+ | [`@viglet/shio-react-sdk`](https://www.npmjs.com/package/@viglet/shio-react-sdk) | React hooks and render components |
102
+ | [`@viglet/shio-sections`](https://www.npmjs.com/package/@viglet/shio-sections) | The page-section vocabulary |
103
+ | [`@viglet/shio`](https://www.npmjs.com/package/@viglet/shio) | The Shio CLI and the MCP bridge for [Claude Code](https://claude.com/claude-code) |
104
+ | [`@viglet/create-shio-app`](https://www.npmjs.com/package/@viglet/create-shio-app) | Next.js starter generator |
105
+
106
+ ## Develop
107
+
108
+ ```bash
109
+ npm run build # vite lib build (es + umd + iife) and .d.ts
110
+ ```
111
+
112
+ ## License
113
+
114
+ Apache-2.0 — [Viglet Shio](https://shio.viglet.org/) ·
115
+ [github.com/openviglet/shio](https://github.com/openviglet/shio) ·
116
+ [docs.viglet.org/shio](https://docs.viglet.org/shio/) ·
117
+ part of the [Viglet](https://www.viglet.org) open source family.
@@ -0,0 +1,99 @@
1
+ /*!
2
+ * @viglet/shio-editor-cors v2026.2.0
3
+ * Shio CMS Universal Editor Bridge
4
+ *
5
+ * Include this script in any page to enable Shio Universal Editor support.
6
+ * Requires: <meta name="urn:shio:system:connection" content="shio:http://your-shio-server">
7
+ *
8
+ * Copyright (C) 2016-2026 Viglet Team
9
+ * Licensed under the Apache License, Version 2.0.
10
+ */
11
+ interface EditorState {
12
+ mode: "preview" | "edit";
13
+ selectedElement: HTMLElement | null;
14
+ activeEditor: ActiveEditor | null;
15
+ changedContent: Record<string, ContentChange>;
16
+ connectionUrl: string | null;
17
+ siteName: string | null;
18
+ folderPath: string | null;
19
+ /**
20
+ * The editor shell's origin, and the bridge is inert without it (SH350).
21
+ *
22
+ * It has to be *told*: a framed page cannot work out who framed it -
23
+ * `document.referrer` is empty on some navigations and `window.parent.location`
24
+ * throws cross-origin - which is why the server-injected bridge is handed
25
+ * `data-shio-editor-origin` at render time. This package is included by the front
26
+ * end itself, so it comes from the same meta tags the connection does.
27
+ */
28
+ parentOrigin: string | null;
29
+ }
30
+ interface ActiveEditor {
31
+ element: HTMLElement;
32
+ info: ElementInfo;
33
+ originalContent: string;
34
+ type: "text" | "richtext";
35
+ toolbar?: HTMLElement;
36
+ }
37
+ interface ElementInfo {
38
+ resource: string | null;
39
+ postId: string | null;
40
+ type: string;
41
+ prop: string | null;
42
+ label: string;
43
+ model: string;
44
+ selector: string;
45
+ }
46
+ interface DomFieldInfo {
47
+ prop: string;
48
+ type: string;
49
+ label: string;
50
+ value: string;
51
+ selector: string;
52
+ }
53
+ interface ContentChange {
54
+ postId: string | null;
55
+ prop: string | null;
56
+ type: string;
57
+ value: string;
58
+ label: string;
59
+ }
60
+ interface EditorMessage {
61
+ type: string;
62
+ data?: Record<string, unknown>;
63
+ }
64
+ declare const MODE_PREVIEW: "preview";
65
+ declare const MODE_EDIT: "edit";
66
+ /**
67
+ * Where the editor shell's origin comes from (SH350).
68
+ *
69
+ * A meta tag rather than a script attribute, because this package is bundled by the front end
70
+ * rather than injected as a tag - and because that is where this bridge already reads its
71
+ * configuration (`urn:shio:system:connection`, `...:site`, `...:path`).
72
+ */
73
+ declare const EDITOR_ORIGIN_META = "urn:shio:system:editor-origin";
74
+ declare const state: EditorState;
75
+ declare function readConnectionMeta(): string | null;
76
+ declare function readMeta(name: string): string | null;
77
+ declare function parseResource(urn: string | null): string | null;
78
+ declare function findEditableParent(el: HTMLElement | null): HTMLElement | null;
79
+ declare function getElementInfo(el: HTMLElement): ElementInfo;
80
+ declare function buildSelector(el: HTMLElement): string;
81
+ declare function getComponentFields(el: HTMLElement): DomFieldInfo[];
82
+ declare function sendToParent(type: string, data: unknown): void;
83
+ declare function onParentMessage(event: MessageEvent): void;
84
+ declare function setMode(mode: "edit" | "preview"): void;
85
+ declare function handleClick(e: MouseEvent): void;
86
+ declare function selectElement(el: HTMLElement): void;
87
+ declare function deselectAll(): void;
88
+ declare function startInlineEdit(el: HTMLElement, info: ElementInfo): void;
89
+ declare function startPlainTextEdit(el: HTMLElement, info: ElementInfo): void;
90
+ declare function startRichTextEdit(el: HTMLElement, info: ElementInfo): void;
91
+ declare function createRichTextToolbar(targetEl: HTMLElement): HTMLElement;
92
+ declare function positionToolbar(toolbar: HTMLElement, el: HTMLElement): void;
93
+ declare function commitEdit(el: HTMLElement, info: ElementInfo, newContent: string, originalContent: string): void;
94
+ declare function closeActiveEditor(): void;
95
+ declare function handleContentPatch(data: Record<string, string> | undefined): void;
96
+ declare function handleRequestContent(): void;
97
+ declare function highlightElement(data: Record<string, string> | undefined): void;
98
+ declare function injectStyles(): void;
99
+ declare function init(): void;
@@ -0,0 +1,104 @@
1
+ (function(){var e=`preview`,t=`edit`,n={mode:e,selectedElement:null,activeEditor:null,changedContent:{},connectionUrl:null,siteName:null,folderPath:null,parentOrigin:null};function r(){let e=document.querySelector(`meta[name="urn:shio:system:connection"]`);if(!e)return null;let t=e.getAttribute(`content`);return t?t.replace(/^shio:/,``):null}function i(e){let t=document.querySelector(`meta[name="${e}"]`);return t&&t.getAttribute(`content`)||null}function a(e){return e&&e.replace(`urn:shio:`,``)||null}function o(e){let t=e;for(;t&&t!==document.body;){if(t.hasAttribute(`data-sh-resource`))return t;t=t.parentElement}return null}function s(e){let t=e.getAttribute(`data-sh-resource`),n=e.getAttribute(`data-sh-type`)||`text`,r=e.getAttribute(`data-sh-prop`),i=e.getAttribute(`data-sh-label`)||r||``,s=e.getAttribute(`data-sh-model`)||``;if(!t||!s){let n=o(e);n&&(t||=n.getAttribute(`data-sh-resource`),s||=n.getAttribute(`data-sh-model`)||``)}return{resource:t,postId:a(t),type:n,prop:r,label:i,model:s,selector:c(e)}}function c(e){if(e.id)return`#`+e.id;let t=[],n=e;for(;n&&n!==document.body;){let e=n.tagName.toLowerCase();if(n.id){t.unshift(`#`+n.id);break}let r=n.parentElement?Array.from(n.parentElement.children).filter(e=>e.tagName===n.tagName):[];if(r.length>1){let t=r.indexOf(n)+1;e+=`:nth-of-type(`+t+`)`}t.unshift(e),n=n.parentElement}return t.join(` > `)}function l(e){let t=[];return e.querySelectorAll(`[data-sh-prop]`).forEach(e=>{let n=e,r=n.getAttribute(`data-sh-type`)||`text`,i;i=r===`media`&&n.tagName===`IMG`?n.src:r===`richtext`?n.innerHTML:n.textContent||``,t.push({prop:n.getAttribute(`data-sh-prop`)||``,type:r,label:n.getAttribute(`data-sh-label`)||n.getAttribute(`data-sh-prop`)||``,value:i,selector:c(n)})}),t}function u(e,t){if(window.parent&&window.parent!==window){if(!n.parentOrigin)return;window.parent.postMessage({type:e,data:t},n.parentOrigin)}}function d(t){if(!n.parentOrigin||t.origin!==n.parentOrigin||!t.data||!t.data.type)return;let r=t.data;switch(r.type){case`sh:mode-change`:f(r.data&&r.data.mode?r.data.mode:e);break;case`sh:content-patch`:C(r.data);break;case`sh:request-content`:w();break;case`sh:highlight-element`:T(r.data)}}function f(r){n.mode=r;let i=document.documentElement;i.classList.remove(`sh-edit-mode`,`sh-preview-mode`),i.classList.add(r===t?`sh-edit-mode`:`sh-preview-mode`),r===e&&(S(),h()),u(`sh:mode-changed`,{mode:r})}function p(e){if(n.mode!==t)return;let r=e.target,i=o(r);if(r.hasAttribute(`data-sh-type`)&&r.hasAttribute(`data-sh-prop`)&&(i=r),!i)return;e.preventDefault(),e.stopPropagation(),m(i);let a=s(i),c=i.hasAttribute(`data-sh-resource`)?i:o(i),d=c?l(c):[];u(`sh:element-selected`,{...a,fields:d,siteName:n.siteName,folderPath:n.folderPath}),a.type===`text`||a.type===`richtext`?g(i,a):a.type===`media`&&u(`sh:media-edit-request`,a)}function m(e){h(),n.selectedElement=e,e.classList.add(`sh-selected`)}function h(){n.selectedElement&&=(n.selectedElement.classList.remove(`sh-selected`),null),document.querySelectorAll(`.sh-selected`).forEach(e=>{e.classList.remove(`sh-selected`)})}function g(e,t){S(),t.type===`text`?_(e,t):t.type===`richtext`&&v(e,t)}function _(e,t){let r=e.textContent||``;e.setAttribute(`contenteditable`,`true`),e.classList.add(`sh-editing`),e.focus();let i=document.createRange();i.selectNodeContents(e);let a=window.getSelection();a&&(a.removeAllRanges(),a.addRange(i)),n.activeEditor={element:e,info:t,originalContent:r,type:`text`};function o(){x(e,t,e.textContent||``,r),e.removeEventListener(`blur`,o),e.removeEventListener(`keydown`,s)}function s(t){t.key===`Enter`&&!t.shiftKey?(t.preventDefault(),e.blur()):t.key===`Escape`&&(e.textContent=r,e.blur())}e.addEventListener(`blur`,o),e.addEventListener(`keydown`,s)}function v(e,t){let r=e.innerHTML;e.setAttribute(`contenteditable`,`true`),e.classList.add(`sh-editing`,`sh-richtext-editing`),e.focus(),n.activeEditor={element:e,info:t,originalContent:r,type:`richtext`};let i=y(e);document.body.appendChild(i),b(i,e),n.activeEditor.toolbar=i;function a(){setTimeout(()=>{i.contains(document.activeElement)||e.contains(document.activeElement)||(x(e,t,e.innerHTML,r),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener(`blur`,a))},200)}e.addEventListener(`blur`,a)}function y(e){let t=document.createElement(`div`);return t.className=`sh-rte-toolbar`,t.setAttribute(`role`,`toolbar`),[{cmd:`bold`,icon:`B`,title:`Bold`},{cmd:`italic`,icon:`I`,title:`Italic`},{cmd:`underline`,icon:`U`,title:`Underline`},{cmd:`insertUnorderedList`,icon:`•`,title:`Bullet List`},{cmd:`insertOrderedList`,icon:`1.`,title:`Numbered List`},{cmd:`createLink`,icon:`🔗`,title:`Insert Link`},{cmd:`removeFormat`,icon:`✘`,title:`Clear Formatting`}].forEach(n=>{let r=document.createElement(`button`);r.type=`button`,r.title=n.title,r.textContent=n.icon,r.className=`sh-rte-btn`,r.addEventListener(`mousedown`,t=>{if(t.preventDefault(),n.cmd===`createLink`){let e=prompt(`Enter URL:`);e&&document.execCommand(n.cmd,!1,e)}else document.execCommand(n.cmd,!1,void 0);e.focus()}),t.appendChild(r)}),t}function b(e,t){let n=t.getBoundingClientRect();e.style.position=`fixed`,e.style.top=Math.max(0,n.top-44)+`px`,e.style.left=n.left+`px`,e.style.zIndex=`999999`}function x(e,t,r,i){if(e.removeAttribute(`contenteditable`),e.classList.remove(`sh-editing`,`sh-richtext-editing`),r!==i){let e=t.postId+`:`+t.prop;n.changedContent[e]={postId:t.postId,prop:t.prop,type:t.type,value:r,label:t.label},u(`sh:content-changed`,{postId:t.postId,prop:t.prop,type:t.type,value:r,label:t.label,selector:t.selector})}n.activeEditor=null}function S(){if(n.activeEditor){let e=n.activeEditor;e.element.removeAttribute(`contenteditable`),e.element.classList.remove(`sh-editing`,`sh-richtext-editing`),e.toolbar&&e.toolbar.parentNode&&e.toolbar.parentNode.removeChild(e.toolbar),n.activeEditor=null}}function C(e){if(!e||!e.selector)return;let t=document.querySelector(e.selector);t&&(e.type===`media`&&t.tagName===`IMG`?t.src=e.value:e.type===`richtext`?t.innerHTML=e.value:t.textContent=e.value)}function w(){let e=document.querySelectorAll(`[data-sh-resource]`),t=[];e.forEach(e=>{t.push(s(e))}),u(`sh:content-map`,{elements:t})}function T(e){if(!e||!e.selector)return;h();let t=document.querySelector(e.selector);t&&(m(t),t.scrollIntoView({behavior:`smooth`,block:`center`}))}function E(){if(document.getElementById(`sh-universal-editor-styles`))return;let e=document.createElement(`style`);e.id=`sh-universal-editor-styles`,e.textContent=`
2
+ /* Edit mode: show outlines on all editable elements */
3
+ html.sh-edit-mode [data-sh-resource] {
4
+ outline: 2px dashed rgba(249, 115, 22, 0.4);
5
+ outline-offset: 4px;
6
+ cursor: pointer;
7
+ position: relative;
8
+ transition: outline 0.2s ease, outline-offset 0.2s ease;
9
+ }
10
+ html.sh-edit-mode [data-sh-resource]:hover {
11
+ outline: 2px solid #f97316;
12
+ outline-offset: 4px;
13
+ }
14
+ /* Label tooltip on hover — uses ::after to avoid conflicts with page ::before */
15
+ html.sh-edit-mode [data-sh-label]:hover::after {
16
+ content: attr(data-sh-label);
17
+ position: absolute;
18
+ top: -28px;
19
+ left: 0;
20
+ right: auto;
21
+ bottom: auto;
22
+ width: auto;
23
+ height: auto;
24
+ background: #f97316;
25
+ color: white;
26
+ padding: 3px 8px;
27
+ font-size: 11px;
28
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
29
+ border-radius: 4px;
30
+ white-space: nowrap;
31
+ z-index: 100000;
32
+ pointer-events: none;
33
+ line-height: 1.4;
34
+ font-weight: 500;
35
+ transform: none;
36
+ opacity: 1;
37
+ display: block;
38
+ border: none;
39
+ box-shadow: none;
40
+ margin: 0;
41
+ }
42
+ /* Selected element */
43
+ html.sh-edit-mode .sh-selected {
44
+ outline: 2px solid #f97316 !important;
45
+ outline-offset: 4px;
46
+ box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.15);
47
+ }
48
+ /* Editing state */
49
+ .sh-editing {
50
+ outline: 2px solid #2563eb !important;
51
+ outline-offset: 2px;
52
+ box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15) !important;
53
+ min-height: 1em;
54
+ }
55
+ /* Rich text toolbar */
56
+ .sh-rte-toolbar {
57
+ display: flex;
58
+ gap: 2px;
59
+ background: #1e293b;
60
+ border-radius: 8px;
61
+ padding: 4px;
62
+ box-shadow: 0 4px 16px rgba(0,0,0,0.2);
63
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
64
+ }
65
+ .sh-rte-btn {
66
+ background: transparent;
67
+ border: none;
68
+ color: #e2e8f0;
69
+ width: 32px;
70
+ height: 32px;
71
+ border-radius: 4px;
72
+ cursor: pointer;
73
+ font-size: 14px;
74
+ font-weight: 600;
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ transition: background 0.15s;
79
+ }
80
+ .sh-rte-btn:hover {
81
+ background: rgba(255,255,255,0.15);
82
+ }
83
+ /* Container type elements */
84
+ html.sh-edit-mode [data-sh-type='container'] {
85
+ outline-style: dashed;
86
+ outline-color: rgba(139, 92, 246, 0.4);
87
+ }
88
+ html.sh-edit-mode [data-sh-type='container']:hover {
89
+ outline-color: #8b5cf6;
90
+ }
91
+ /* Component type elements */
92
+ html.sh-edit-mode [data-sh-type='component'] {
93
+ outline-style: dashed;
94
+ outline-color: rgba(16, 185, 129, 0.4);
95
+ }
96
+ html.sh-edit-mode [data-sh-type='component']:hover {
97
+ outline-color: #10b981;
98
+ }
99
+ /* Preview mode: remove all outlines */
100
+ html.sh-preview-mode [data-sh-resource] {
101
+ outline: none !important;
102
+ cursor: default;
103
+ }
104
+ `,document.head.appendChild(e)}function D(){if(window!==window.parent){if(n.parentOrigin=i(`urn:shio:system:editor-origin`),!n.parentOrigin){console.warn(`[shio-editor] inert: add <meta name="urn:shio:system:editor-origin" content="https://your-console-origin"> so this page knows which origin may edit it.`);return}n.connectionUrl=r(),n.siteName=i(`urn:shio:system:site`),n.folderPath=i(`urn:shio:system:path`),E(),window.addEventListener(`message`,d),document.addEventListener(`click`,p,!0),u(`sh:ready`,{url:window.location.href,title:document.title,editableCount:document.querySelectorAll(`[data-sh-resource]`).length,connectionUrl:n.connectionUrl,siteName:n.siteName,folderPath:n.folderPath})}}document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,D):D()})();
@@ -0,0 +1,292 @@
1
+ //#region src/shio-editor-cors.ts
2
+ var e = "preview", t = "edit", n = {
3
+ mode: e,
4
+ selectedElement: null,
5
+ activeEditor: null,
6
+ changedContent: {},
7
+ connectionUrl: null,
8
+ siteName: null,
9
+ folderPath: null,
10
+ parentOrigin: null
11
+ };
12
+ function r() {
13
+ let e = document.querySelector("meta[name=\"urn:shio:system:connection\"]");
14
+ if (!e) return null;
15
+ let t = e.getAttribute("content");
16
+ return t ? t.replace(/^shio:/, "") : null;
17
+ }
18
+ function i(e) {
19
+ let t = document.querySelector(`meta[name="${e}"]`);
20
+ return t && t.getAttribute("content") || null;
21
+ }
22
+ function a(e) {
23
+ return e && e.replace("urn:shio:", "") || null;
24
+ }
25
+ function o(e) {
26
+ let t = e;
27
+ for (; t && t !== document.body;) {
28
+ if (t.hasAttribute("data-sh-resource")) return t;
29
+ t = t.parentElement;
30
+ }
31
+ return null;
32
+ }
33
+ function s(e) {
34
+ let t = e.getAttribute("data-sh-resource"), n = e.getAttribute("data-sh-type") || "text", r = e.getAttribute("data-sh-prop"), i = e.getAttribute("data-sh-label") || r || "", s = e.getAttribute("data-sh-model") || "";
35
+ if (!t || !s) {
36
+ let n = o(e);
37
+ n && (t ||= n.getAttribute("data-sh-resource"), s ||= n.getAttribute("data-sh-model") || "");
38
+ }
39
+ return {
40
+ resource: t,
41
+ postId: a(t),
42
+ type: n,
43
+ prop: r,
44
+ label: i,
45
+ model: s,
46
+ selector: c(e)
47
+ };
48
+ }
49
+ function c(e) {
50
+ if (e.id) return "#" + e.id;
51
+ let t = [], n = e;
52
+ for (; n && n !== document.body;) {
53
+ let e = n.tagName.toLowerCase();
54
+ if (n.id) {
55
+ t.unshift("#" + n.id);
56
+ break;
57
+ }
58
+ let r = n.parentElement ? Array.from(n.parentElement.children).filter((e) => e.tagName === n.tagName) : [];
59
+ if (r.length > 1) {
60
+ let t = r.indexOf(n) + 1;
61
+ e += ":nth-of-type(" + t + ")";
62
+ }
63
+ t.unshift(e), n = n.parentElement;
64
+ }
65
+ return t.join(" > ");
66
+ }
67
+ function l(e) {
68
+ let t = [];
69
+ return e.querySelectorAll("[data-sh-prop]").forEach((e) => {
70
+ let n = e, r = n.getAttribute("data-sh-type") || "text", i;
71
+ i = r === "media" && n.tagName === "IMG" ? n.src : r === "richtext" ? n.innerHTML : n.textContent || "", t.push({
72
+ prop: n.getAttribute("data-sh-prop") || "",
73
+ type: r,
74
+ label: n.getAttribute("data-sh-label") || n.getAttribute("data-sh-prop") || "",
75
+ value: i,
76
+ selector: c(n)
77
+ });
78
+ }), t;
79
+ }
80
+ function u(e, t) {
81
+ if (window.parent && window.parent !== window) {
82
+ if (!n.parentOrigin) return;
83
+ window.parent.postMessage({
84
+ type: e,
85
+ data: t
86
+ }, n.parentOrigin);
87
+ }
88
+ }
89
+ function d(t) {
90
+ if (!n.parentOrigin || t.origin !== n.parentOrigin || !t.data || !t.data.type) return;
91
+ let r = t.data;
92
+ switch (r.type) {
93
+ case "sh:mode-change":
94
+ f(r.data && r.data.mode ? r.data.mode : e);
95
+ break;
96
+ case "sh:content-patch":
97
+ C(r.data);
98
+ break;
99
+ case "sh:request-content":
100
+ w();
101
+ break;
102
+ case "sh:highlight-element": T(r.data);
103
+ }
104
+ }
105
+ function f(r) {
106
+ n.mode = r;
107
+ let i = document.documentElement;
108
+ i.classList.remove("sh-edit-mode", "sh-preview-mode"), i.classList.add(r === t ? "sh-edit-mode" : "sh-preview-mode"), r === e && (S(), h()), u("sh:mode-changed", { mode: r });
109
+ }
110
+ function p(e) {
111
+ if (n.mode !== t) return;
112
+ let r = e.target, i = o(r);
113
+ if (r.hasAttribute("data-sh-type") && r.hasAttribute("data-sh-prop") && (i = r), !i) return;
114
+ e.preventDefault(), e.stopPropagation(), m(i);
115
+ let a = s(i), c = i.hasAttribute("data-sh-resource") ? i : o(i), d = c ? l(c) : [];
116
+ u("sh:element-selected", {
117
+ ...a,
118
+ fields: d,
119
+ siteName: n.siteName,
120
+ folderPath: n.folderPath
121
+ }), a.type === "text" || a.type === "richtext" ? g(i, a) : a.type === "media" && u("sh:media-edit-request", a);
122
+ }
123
+ function m(e) {
124
+ h(), n.selectedElement = e, e.classList.add("sh-selected");
125
+ }
126
+ function h() {
127
+ n.selectedElement &&= (n.selectedElement.classList.remove("sh-selected"), null), document.querySelectorAll(".sh-selected").forEach((e) => {
128
+ e.classList.remove("sh-selected");
129
+ });
130
+ }
131
+ function g(e, t) {
132
+ S(), t.type === "text" ? _(e, t) : t.type === "richtext" && v(e, t);
133
+ }
134
+ function _(e, t) {
135
+ let r = e.textContent || "";
136
+ e.setAttribute("contenteditable", "true"), e.classList.add("sh-editing"), e.focus();
137
+ let i = document.createRange();
138
+ i.selectNodeContents(e);
139
+ let a = window.getSelection();
140
+ a && (a.removeAllRanges(), a.addRange(i)), n.activeEditor = {
141
+ element: e,
142
+ info: t,
143
+ originalContent: r,
144
+ type: "text"
145
+ };
146
+ function o() {
147
+ x(e, t, e.textContent || "", r), e.removeEventListener("blur", o), e.removeEventListener("keydown", s);
148
+ }
149
+ function s(t) {
150
+ t.key === "Enter" && !t.shiftKey ? (t.preventDefault(), e.blur()) : t.key === "Escape" && (e.textContent = r, e.blur());
151
+ }
152
+ e.addEventListener("blur", o), e.addEventListener("keydown", s);
153
+ }
154
+ function v(e, t) {
155
+ let r = e.innerHTML;
156
+ e.setAttribute("contenteditable", "true"), e.classList.add("sh-editing", "sh-richtext-editing"), e.focus(), n.activeEditor = {
157
+ element: e,
158
+ info: t,
159
+ originalContent: r,
160
+ type: "richtext"
161
+ };
162
+ let i = y(e);
163
+ document.body.appendChild(i), b(i, e), n.activeEditor.toolbar = i;
164
+ function a() {
165
+ setTimeout(() => {
166
+ i.contains(document.activeElement) || e.contains(document.activeElement) || (x(e, t, e.innerHTML, r), i.parentNode && i.parentNode.removeChild(i), e.removeEventListener("blur", a));
167
+ }, 200);
168
+ }
169
+ e.addEventListener("blur", a);
170
+ }
171
+ function y(e) {
172
+ let t = document.createElement("div");
173
+ return t.className = "sh-rte-toolbar", t.setAttribute("role", "toolbar"), [
174
+ {
175
+ cmd: "bold",
176
+ icon: "B",
177
+ title: "Bold"
178
+ },
179
+ {
180
+ cmd: "italic",
181
+ icon: "I",
182
+ title: "Italic"
183
+ },
184
+ {
185
+ cmd: "underline",
186
+ icon: "U",
187
+ title: "Underline"
188
+ },
189
+ {
190
+ cmd: "insertUnorderedList",
191
+ icon: "•",
192
+ title: "Bullet List"
193
+ },
194
+ {
195
+ cmd: "insertOrderedList",
196
+ icon: "1.",
197
+ title: "Numbered List"
198
+ },
199
+ {
200
+ cmd: "createLink",
201
+ icon: "🔗",
202
+ title: "Insert Link"
203
+ },
204
+ {
205
+ cmd: "removeFormat",
206
+ icon: "✘",
207
+ title: "Clear Formatting"
208
+ }
209
+ ].forEach((n) => {
210
+ let r = document.createElement("button");
211
+ r.type = "button", r.title = n.title, r.textContent = n.icon, r.className = "sh-rte-btn", r.addEventListener("mousedown", (t) => {
212
+ if (t.preventDefault(), n.cmd === "createLink") {
213
+ let e = prompt("Enter URL:");
214
+ e && document.execCommand(n.cmd, !1, e);
215
+ } else document.execCommand(n.cmd, !1, void 0);
216
+ e.focus();
217
+ }), t.appendChild(r);
218
+ }), t;
219
+ }
220
+ function b(e, t) {
221
+ let n = t.getBoundingClientRect();
222
+ e.style.position = "fixed", e.style.top = Math.max(0, n.top - 44) + "px", e.style.left = n.left + "px", e.style.zIndex = "999999";
223
+ }
224
+ function x(e, t, r, i) {
225
+ if (e.removeAttribute("contenteditable"), e.classList.remove("sh-editing", "sh-richtext-editing"), r !== i) {
226
+ let e = t.postId + ":" + t.prop;
227
+ n.changedContent[e] = {
228
+ postId: t.postId,
229
+ prop: t.prop,
230
+ type: t.type,
231
+ value: r,
232
+ label: t.label
233
+ }, u("sh:content-changed", {
234
+ postId: t.postId,
235
+ prop: t.prop,
236
+ type: t.type,
237
+ value: r,
238
+ label: t.label,
239
+ selector: t.selector
240
+ });
241
+ }
242
+ n.activeEditor = null;
243
+ }
244
+ function S() {
245
+ if (n.activeEditor) {
246
+ let e = n.activeEditor;
247
+ e.element.removeAttribute("contenteditable"), e.element.classList.remove("sh-editing", "sh-richtext-editing"), e.toolbar && e.toolbar.parentNode && e.toolbar.parentNode.removeChild(e.toolbar), n.activeEditor = null;
248
+ }
249
+ }
250
+ function C(e) {
251
+ if (!e || !e.selector) return;
252
+ let t = document.querySelector(e.selector);
253
+ t && (e.type === "media" && t.tagName === "IMG" ? t.src = e.value : e.type === "richtext" ? t.innerHTML = e.value : t.textContent = e.value);
254
+ }
255
+ function w() {
256
+ let e = document.querySelectorAll("[data-sh-resource]"), t = [];
257
+ e.forEach((e) => {
258
+ t.push(s(e));
259
+ }), u("sh:content-map", { elements: t });
260
+ }
261
+ function T(e) {
262
+ if (!e || !e.selector) return;
263
+ h();
264
+ let t = document.querySelector(e.selector);
265
+ t && (m(t), t.scrollIntoView({
266
+ behavior: "smooth",
267
+ block: "center"
268
+ }));
269
+ }
270
+ function E() {
271
+ if (document.getElementById("sh-universal-editor-styles")) return;
272
+ let e = document.createElement("style");
273
+ e.id = "sh-universal-editor-styles", e.textContent = "\n /* Edit mode: show outlines on all editable elements */\n html.sh-edit-mode [data-sh-resource] {\n outline: 2px dashed rgba(249, 115, 22, 0.4);\n outline-offset: 4px;\n cursor: pointer;\n position: relative;\n transition: outline 0.2s ease, outline-offset 0.2s ease;\n }\n html.sh-edit-mode [data-sh-resource]:hover {\n outline: 2px solid #f97316;\n outline-offset: 4px;\n }\n /* Label tooltip on hover — uses ::after to avoid conflicts with page ::before */\n html.sh-edit-mode [data-sh-label]:hover::after {\n content: attr(data-sh-label);\n position: absolute;\n top: -28px;\n left: 0;\n right: auto;\n bottom: auto;\n width: auto;\n height: auto;\n background: #f97316;\n color: white;\n padding: 3px 8px;\n font-size: 11px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n border-radius: 4px;\n white-space: nowrap;\n z-index: 100000;\n pointer-events: none;\n line-height: 1.4;\n font-weight: 500;\n transform: none;\n opacity: 1;\n display: block;\n border: none;\n box-shadow: none;\n margin: 0;\n }\n /* Selected element */\n html.sh-edit-mode .sh-selected {\n outline: 2px solid #f97316 !important;\n outline-offset: 4px;\n box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.15);\n }\n /* Editing state */\n .sh-editing {\n outline: 2px solid #2563eb !important;\n outline-offset: 2px;\n box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15) !important;\n min-height: 1em;\n }\n /* Rich text toolbar */\n .sh-rte-toolbar {\n display: flex;\n gap: 2px;\n background: #1e293b;\n border-radius: 8px;\n padding: 4px;\n box-shadow: 0 4px 16px rgba(0,0,0,0.2);\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n }\n .sh-rte-btn {\n background: transparent;\n border: none;\n color: #e2e8f0;\n width: 32px;\n height: 32px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 600;\n display: flex;\n align-items: center;\n justify-content: center;\n transition: background 0.15s;\n }\n .sh-rte-btn:hover {\n background: rgba(255,255,255,0.15);\n }\n /* Container type elements */\n html.sh-edit-mode [data-sh-type='container'] {\n outline-style: dashed;\n outline-color: rgba(139, 92, 246, 0.4);\n }\n html.sh-edit-mode [data-sh-type='container']:hover {\n outline-color: #8b5cf6;\n }\n /* Component type elements */\n html.sh-edit-mode [data-sh-type='component'] {\n outline-style: dashed;\n outline-color: rgba(16, 185, 129, 0.4);\n }\n html.sh-edit-mode [data-sh-type='component']:hover {\n outline-color: #10b981;\n }\n /* Preview mode: remove all outlines */\n html.sh-preview-mode [data-sh-resource] {\n outline: none !important;\n cursor: default;\n }\n ", document.head.appendChild(e);
274
+ }
275
+ function D() {
276
+ if (window !== window.parent) {
277
+ if (n.parentOrigin = i("urn:shio:system:editor-origin"), !n.parentOrigin) {
278
+ console.warn("[shio-editor] inert: add <meta name=\"urn:shio:system:editor-origin\" content=\"https://your-console-origin\"> so this page knows which origin may edit it.");
279
+ return;
280
+ }
281
+ n.connectionUrl = r(), n.siteName = i("urn:shio:system:site"), n.folderPath = i("urn:shio:system:path"), E(), window.addEventListener("message", d), document.addEventListener("click", p, !0), u("sh:ready", {
282
+ url: window.location.href,
283
+ title: document.title,
284
+ editableCount: document.querySelectorAll("[data-sh-resource]").length,
285
+ connectionUrl: n.connectionUrl,
286
+ siteName: n.siteName,
287
+ folderPath: n.folderPath
288
+ });
289
+ }
290
+ }
291
+ document.readyState === "loading" ? document.addEventListener("DOMContentLoaded", D) : D();
292
+ //#endregion
@@ -0,0 +1,104 @@
1
+ (function(e){typeof define==`function`&&define.amd?define([],e):e()})(function(){var e=`preview`,t=`edit`,n={mode:e,selectedElement:null,activeEditor:null,changedContent:{},connectionUrl:null,siteName:null,folderPath:null,parentOrigin:null};function r(){let e=document.querySelector(`meta[name="urn:shio:system:connection"]`);if(!e)return null;let t=e.getAttribute(`content`);return t?t.replace(/^shio:/,``):null}function i(e){let t=document.querySelector(`meta[name="${e}"]`);return t&&t.getAttribute(`content`)||null}function a(e){return e&&e.replace(`urn:shio:`,``)||null}function o(e){let t=e;for(;t&&t!==document.body;){if(t.hasAttribute(`data-sh-resource`))return t;t=t.parentElement}return null}function s(e){let t=e.getAttribute(`data-sh-resource`),n=e.getAttribute(`data-sh-type`)||`text`,r=e.getAttribute(`data-sh-prop`),i=e.getAttribute(`data-sh-label`)||r||``,s=e.getAttribute(`data-sh-model`)||``;if(!t||!s){let n=o(e);n&&(t||=n.getAttribute(`data-sh-resource`),s||=n.getAttribute(`data-sh-model`)||``)}return{resource:t,postId:a(t),type:n,prop:r,label:i,model:s,selector:c(e)}}function c(e){if(e.id)return`#`+e.id;let t=[],n=e;for(;n&&n!==document.body;){let e=n.tagName.toLowerCase();if(n.id){t.unshift(`#`+n.id);break}let r=n.parentElement?Array.from(n.parentElement.children).filter(e=>e.tagName===n.tagName):[];if(r.length>1){let t=r.indexOf(n)+1;e+=`:nth-of-type(`+t+`)`}t.unshift(e),n=n.parentElement}return t.join(` > `)}function l(e){let t=[];return e.querySelectorAll(`[data-sh-prop]`).forEach(e=>{let n=e,r=n.getAttribute(`data-sh-type`)||`text`,i;i=r===`media`&&n.tagName===`IMG`?n.src:r===`richtext`?n.innerHTML:n.textContent||``,t.push({prop:n.getAttribute(`data-sh-prop`)||``,type:r,label:n.getAttribute(`data-sh-label`)||n.getAttribute(`data-sh-prop`)||``,value:i,selector:c(n)})}),t}function u(e,t){if(window.parent&&window.parent!==window){if(!n.parentOrigin)return;window.parent.postMessage({type:e,data:t},n.parentOrigin)}}function d(t){if(!n.parentOrigin||t.origin!==n.parentOrigin||!t.data||!t.data.type)return;let r=t.data;switch(r.type){case`sh:mode-change`:f(r.data&&r.data.mode?r.data.mode:e);break;case`sh:content-patch`:C(r.data);break;case`sh:request-content`:w();break;case`sh:highlight-element`:T(r.data)}}function f(r){n.mode=r;let i=document.documentElement;i.classList.remove(`sh-edit-mode`,`sh-preview-mode`),i.classList.add(r===t?`sh-edit-mode`:`sh-preview-mode`),r===e&&(S(),h()),u(`sh:mode-changed`,{mode:r})}function p(e){if(n.mode!==t)return;let r=e.target,i=o(r);if(r.hasAttribute(`data-sh-type`)&&r.hasAttribute(`data-sh-prop`)&&(i=r),!i)return;e.preventDefault(),e.stopPropagation(),m(i);let a=s(i),c=i.hasAttribute(`data-sh-resource`)?i:o(i),d=c?l(c):[];u(`sh:element-selected`,{...a,fields:d,siteName:n.siteName,folderPath:n.folderPath}),a.type===`text`||a.type===`richtext`?g(i,a):a.type===`media`&&u(`sh:media-edit-request`,a)}function m(e){h(),n.selectedElement=e,e.classList.add(`sh-selected`)}function h(){n.selectedElement&&=(n.selectedElement.classList.remove(`sh-selected`),null),document.querySelectorAll(`.sh-selected`).forEach(e=>{e.classList.remove(`sh-selected`)})}function g(e,t){S(),t.type===`text`?_(e,t):t.type===`richtext`&&v(e,t)}function _(e,t){let r=e.textContent||``;e.setAttribute(`contenteditable`,`true`),e.classList.add(`sh-editing`),e.focus();let i=document.createRange();i.selectNodeContents(e);let a=window.getSelection();a&&(a.removeAllRanges(),a.addRange(i)),n.activeEditor={element:e,info:t,originalContent:r,type:`text`};function o(){x(e,t,e.textContent||``,r),e.removeEventListener(`blur`,o),e.removeEventListener(`keydown`,s)}function s(t){t.key===`Enter`&&!t.shiftKey?(t.preventDefault(),e.blur()):t.key===`Escape`&&(e.textContent=r,e.blur())}e.addEventListener(`blur`,o),e.addEventListener(`keydown`,s)}function v(e,t){let r=e.innerHTML;e.setAttribute(`contenteditable`,`true`),e.classList.add(`sh-editing`,`sh-richtext-editing`),e.focus(),n.activeEditor={element:e,info:t,originalContent:r,type:`richtext`};let i=y(e);document.body.appendChild(i),b(i,e),n.activeEditor.toolbar=i;function a(){setTimeout(()=>{i.contains(document.activeElement)||e.contains(document.activeElement)||(x(e,t,e.innerHTML,r),i.parentNode&&i.parentNode.removeChild(i),e.removeEventListener(`blur`,a))},200)}e.addEventListener(`blur`,a)}function y(e){let t=document.createElement(`div`);return t.className=`sh-rte-toolbar`,t.setAttribute(`role`,`toolbar`),[{cmd:`bold`,icon:`B`,title:`Bold`},{cmd:`italic`,icon:`I`,title:`Italic`},{cmd:`underline`,icon:`U`,title:`Underline`},{cmd:`insertUnorderedList`,icon:`•`,title:`Bullet List`},{cmd:`insertOrderedList`,icon:`1.`,title:`Numbered List`},{cmd:`createLink`,icon:`🔗`,title:`Insert Link`},{cmd:`removeFormat`,icon:`✘`,title:`Clear Formatting`}].forEach(n=>{let r=document.createElement(`button`);r.type=`button`,r.title=n.title,r.textContent=n.icon,r.className=`sh-rte-btn`,r.addEventListener(`mousedown`,t=>{if(t.preventDefault(),n.cmd===`createLink`){let e=prompt(`Enter URL:`);e&&document.execCommand(n.cmd,!1,e)}else document.execCommand(n.cmd,!1,void 0);e.focus()}),t.appendChild(r)}),t}function b(e,t){let n=t.getBoundingClientRect();e.style.position=`fixed`,e.style.top=Math.max(0,n.top-44)+`px`,e.style.left=n.left+`px`,e.style.zIndex=`999999`}function x(e,t,r,i){if(e.removeAttribute(`contenteditable`),e.classList.remove(`sh-editing`,`sh-richtext-editing`),r!==i){let e=t.postId+`:`+t.prop;n.changedContent[e]={postId:t.postId,prop:t.prop,type:t.type,value:r,label:t.label},u(`sh:content-changed`,{postId:t.postId,prop:t.prop,type:t.type,value:r,label:t.label,selector:t.selector})}n.activeEditor=null}function S(){if(n.activeEditor){let e=n.activeEditor;e.element.removeAttribute(`contenteditable`),e.element.classList.remove(`sh-editing`,`sh-richtext-editing`),e.toolbar&&e.toolbar.parentNode&&e.toolbar.parentNode.removeChild(e.toolbar),n.activeEditor=null}}function C(e){if(!e||!e.selector)return;let t=document.querySelector(e.selector);t&&(e.type===`media`&&t.tagName===`IMG`?t.src=e.value:e.type===`richtext`?t.innerHTML=e.value:t.textContent=e.value)}function w(){let e=document.querySelectorAll(`[data-sh-resource]`),t=[];e.forEach(e=>{t.push(s(e))}),u(`sh:content-map`,{elements:t})}function T(e){if(!e||!e.selector)return;h();let t=document.querySelector(e.selector);t&&(m(t),t.scrollIntoView({behavior:`smooth`,block:`center`}))}function E(){if(document.getElementById(`sh-universal-editor-styles`))return;let e=document.createElement(`style`);e.id=`sh-universal-editor-styles`,e.textContent=`
2
+ /* Edit mode: show outlines on all editable elements */
3
+ html.sh-edit-mode [data-sh-resource] {
4
+ outline: 2px dashed rgba(249, 115, 22, 0.4);
5
+ outline-offset: 4px;
6
+ cursor: pointer;
7
+ position: relative;
8
+ transition: outline 0.2s ease, outline-offset 0.2s ease;
9
+ }
10
+ html.sh-edit-mode [data-sh-resource]:hover {
11
+ outline: 2px solid #f97316;
12
+ outline-offset: 4px;
13
+ }
14
+ /* Label tooltip on hover — uses ::after to avoid conflicts with page ::before */
15
+ html.sh-edit-mode [data-sh-label]:hover::after {
16
+ content: attr(data-sh-label);
17
+ position: absolute;
18
+ top: -28px;
19
+ left: 0;
20
+ right: auto;
21
+ bottom: auto;
22
+ width: auto;
23
+ height: auto;
24
+ background: #f97316;
25
+ color: white;
26
+ padding: 3px 8px;
27
+ font-size: 11px;
28
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
29
+ border-radius: 4px;
30
+ white-space: nowrap;
31
+ z-index: 100000;
32
+ pointer-events: none;
33
+ line-height: 1.4;
34
+ font-weight: 500;
35
+ transform: none;
36
+ opacity: 1;
37
+ display: block;
38
+ border: none;
39
+ box-shadow: none;
40
+ margin: 0;
41
+ }
42
+ /* Selected element */
43
+ html.sh-edit-mode .sh-selected {
44
+ outline: 2px solid #f97316 !important;
45
+ outline-offset: 4px;
46
+ box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.15);
47
+ }
48
+ /* Editing state */
49
+ .sh-editing {
50
+ outline: 2px solid #2563eb !important;
51
+ outline-offset: 2px;
52
+ box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15) !important;
53
+ min-height: 1em;
54
+ }
55
+ /* Rich text toolbar */
56
+ .sh-rte-toolbar {
57
+ display: flex;
58
+ gap: 2px;
59
+ background: #1e293b;
60
+ border-radius: 8px;
61
+ padding: 4px;
62
+ box-shadow: 0 4px 16px rgba(0,0,0,0.2);
63
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
64
+ }
65
+ .sh-rte-btn {
66
+ background: transparent;
67
+ border: none;
68
+ color: #e2e8f0;
69
+ width: 32px;
70
+ height: 32px;
71
+ border-radius: 4px;
72
+ cursor: pointer;
73
+ font-size: 14px;
74
+ font-weight: 600;
75
+ display: flex;
76
+ align-items: center;
77
+ justify-content: center;
78
+ transition: background 0.15s;
79
+ }
80
+ .sh-rte-btn:hover {
81
+ background: rgba(255,255,255,0.15);
82
+ }
83
+ /* Container type elements */
84
+ html.sh-edit-mode [data-sh-type='container'] {
85
+ outline-style: dashed;
86
+ outline-color: rgba(139, 92, 246, 0.4);
87
+ }
88
+ html.sh-edit-mode [data-sh-type='container']:hover {
89
+ outline-color: #8b5cf6;
90
+ }
91
+ /* Component type elements */
92
+ html.sh-edit-mode [data-sh-type='component'] {
93
+ outline-style: dashed;
94
+ outline-color: rgba(16, 185, 129, 0.4);
95
+ }
96
+ html.sh-edit-mode [data-sh-type='component']:hover {
97
+ outline-color: #10b981;
98
+ }
99
+ /* Preview mode: remove all outlines */
100
+ html.sh-preview-mode [data-sh-resource] {
101
+ outline: none !important;
102
+ cursor: default;
103
+ }
104
+ `,document.head.appendChild(e)}function D(){if(window!==window.parent){if(n.parentOrigin=i(`urn:shio:system:editor-origin`),!n.parentOrigin){console.warn(`[shio-editor] inert: add <meta name="urn:shio:system:editor-origin" content="https://your-console-origin"> so this page knows which origin may edit it.`);return}n.connectionUrl=r(),n.siteName=i(`urn:shio:system:site`),n.folderPath=i(`urn:shio:system:path`),E(),window.addEventListener(`message`,d),document.addEventListener(`click`,p,!0),u(`sh:ready`,{url:window.location.href,title:document.title,editableCount:document.querySelectorAll(`[data-sh-resource]`).length,connectionUrl:n.connectionUrl,siteName:n.siteName,folderPath:n.folderPath})}}document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,D):D()});
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@viglet/shio-editor-cors",
3
+ "version": "2026.3.2",
4
+ "description": "Shio CMS Universal Editor bridge - enables inline visual editing for any page",
5
+ "homepage": "https://shio.viglet.org/",
6
+ "type": "module",
7
+ "main": "dist/shio-editor-cors.umd.cjs",
8
+ "module": "dist/shio-editor-cors.js",
9
+ "types": "dist/shio-editor-cors.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/shio-editor-cors.d.ts",
13
+ "import": "./dist/shio-editor-cors.js",
14
+ "require": "./dist/shio-editor-cors.umd.cjs"
15
+ },
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "shio",
23
+ "viglet",
24
+ "cms",
25
+ "headless-cms",
26
+ "content-management-system",
27
+ "agent",
28
+ "ai",
29
+ "mcp",
30
+ "model-context-protocol",
31
+ "claude-code",
32
+ "universal-editor",
33
+ "visual-editing",
34
+ "inline-editing",
35
+ "wysiwyg",
36
+ "live-preview",
37
+ "headless"
38
+ ],
39
+ "author": {
40
+ "name": "Viglet Team",
41
+ "url": "https://www.viglet.org"
42
+ },
43
+ "license": "Apache-2.0",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/openviglet/shio.git",
47
+ "directory": "shio-js-sdk"
48
+ },
49
+ "bugs": {
50
+ "url": "https://github.com/openviglet/shio/issues"
51
+ },
52
+ "devDependencies": {
53
+ "vite": "^8.2.0",
54
+ "typescript": "^5.8.3"
55
+ },
56
+ "scripts": {
57
+ "dev": "vite build --watch",
58
+ "build": "vite build && tsc --emitDeclarationOnly"
59
+ }
60
+ }