@zeke-02/docx-editor 0.5.3 → 0.5.4
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/dist/{KeyboardShortcutsDialog-5D_FoAp6.d.ts → KeyboardShortcutsDialog-B0UFuR4w.d.ts} +2 -2
- package/dist/{KeyboardShortcutsDialog-D7ihAj18.d.mts → KeyboardShortcutsDialog-t6JKL4Aj.d.mts} +2 -2
- package/dist/PageSetupDialog-642IAVG2.js +1 -1
- package/dist/PageSetupDialog-ERUQDHAY.mjs +1 -1
- package/dist/PluginHost-HS31VIuo.d.mts +16 -0
- package/dist/PluginHost-zILZO7zX.d.ts +16 -0
- package/dist/{agentApi-D4AZmNfB.d.ts → agentApi-B2Y7kexW.d.ts} +1 -1
- package/dist/{agentApi-C41hiW-n.d.mts → agentApi-BzUJ_kao.d.mts} +1 -1
- package/dist/{chunk-E6MQXELR.js → chunk-HXDMASAR.js} +1 -1
- package/dist/chunk-JFRDFK7V.mjs +260 -0
- package/dist/{chunk-LUJ6HCMH.mjs → chunk-LWOHVYKW.mjs} +1 -1
- package/dist/chunk-MDTA25AN.mjs +60 -0
- package/dist/chunk-NOLMVQNN.mjs +40 -0
- package/dist/chunk-SGTUE33R.js +260 -0
- package/dist/chunk-WO3FIV4B.js +40 -0
- package/dist/{chunk-ONNHQWAX.mjs → chunk-XGJ2EORY.mjs} +1 -1
- package/dist/{chunk-AYMGSTNG.js → chunk-Y3SEHWZ2.js} +1 -1
- package/dist/chunk-YBEVHQCT.js +60 -0
- package/dist/{content-B2MzIMwA.d.mts → content-REFGFfEH.d.mts} +1 -1
- package/dist/{content-B2MzIMwA.d.ts → content-REFGFfEH.d.ts} +1 -1
- package/dist/dialogs.d.mts +4 -4
- package/dist/dialogs.d.ts +4 -4
- package/dist/dialogs.js +1 -1
- package/dist/dialogs.mjs +1 -1
- package/dist/{document-Di1qGqLS.d.mts → document-Cu2vq_wS.d.mts} +1 -1
- package/dist/{document-DZ_ZeZEH.d.ts → document-CxOagoLQ.d.ts} +1 -1
- package/dist/executor-WBHID2RK.mjs +1 -0
- package/dist/{executor-EPEB53SJ.js → executor-Y5VUOAHY.js} +1 -1
- package/dist/{findReplace-pkMskVJU.d.ts → findReplace-Bue0JaXh.d.ts} +1 -1
- package/dist/{findReplace-CpIoILbP.d.mts → findReplace-shXbOjFQ.d.mts} +1 -1
- package/dist/fork.css +1 -0
- package/dist/fork.d.mts +535 -0
- package/dist/fork.d.ts +535 -0
- package/dist/fork.js +1 -0
- package/dist/fork.mjs +1 -0
- package/dist/hooks.d.mts +6 -6
- package/dist/hooks.d.ts +6 -6
- package/dist/hooks.js +1 -1
- package/dist/hooks.mjs +1 -1
- package/dist/index-B5A-J9GC.d.ts +1119 -0
- package/dist/index-bw-PaozF.d.mts +1119 -0
- package/dist/index.d.mts +11 -1120
- package/dist/index.d.ts +11 -1120
- package/dist/index.js +1 -40
- package/dist/index.mjs +1 -40
- package/dist/plugin-api.d.mts +5 -16
- package/dist/plugin-api.d.ts +5 -16
- package/dist/plugin-api.js +1 -260
- package/dist/plugin-api.mjs +1 -260
- package/dist/{types-DZUhB7Ao.d.mts → types-BF48VxkC.d.mts} +1 -1
- package/dist/{types-DZUhB7Ao.d.ts → types-BF48VxkC.d.ts} +1 -1
- package/dist/{types-Bd_YzkhG.d.mts → types-BnIs4sE7.d.mts} +1 -1
- package/dist/{types-Bd_YzkhG.d.ts → types-BnIs4sE7.d.ts} +1 -1
- package/dist/{types-DcxHFUSc.d.ts → types-CW6HFAX6.d.ts} +1 -1
- package/dist/{types-CkfDgB0O.d.mts → types-DIsDCwTG.d.mts} +1 -1
- package/dist/ui.d.mts +9 -9
- package/dist/ui.d.ts +9 -9
- package/dist/ui.js +1 -1
- package/dist/ui.mjs +1 -1
- package/dist/{useFindReplace-eyhMSZZf.d.ts → useFindReplace-DKy-s3gS.d.ts} +2 -2
- package/dist/{useFindReplace-DDs533b-.d.mts → useFindReplace-vuoKpDKE.d.mts} +2 -2
- package/package.json +7 -7
- package/dist/chunk-47VJOBJD.mjs +0 -60
- package/dist/chunk-IP5NAYHL.js +0 -60
- package/dist/executor-TVJ6K6MW.mjs +0 -1
package/dist/{KeyboardShortcutsDialog-5D_FoAp6.d.ts → KeyboardShortcutsDialog-B0UFuR4w.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default, { CSSProperties } from 'react';
|
|
2
|
-
import { a as FindOptions, b as FindResult, F as FindMatch, P as ParsedClipboardContent } from './findReplace-
|
|
3
|
-
import {
|
|
2
|
+
import { a as FindOptions, b as FindResult, F as FindMatch, P as ParsedClipboardContent } from './findReplace-Bue0JaXh.js';
|
|
3
|
+
import { T as TranslationKey } from './types-BF48VxkC.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Find and Replace Dialog Component
|
package/dist/{KeyboardShortcutsDialog-D7ihAj18.d.mts → KeyboardShortcutsDialog-t6JKL4Aj.d.mts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default, { CSSProperties } from 'react';
|
|
2
|
-
import { a as FindOptions, b as FindResult, F as FindMatch, P as ParsedClipboardContent } from './findReplace-
|
|
3
|
-
import {
|
|
2
|
+
import { a as FindOptions, b as FindResult, F as FindMatch, P as ParsedClipboardContent } from './findReplace-shXbOjFQ.mjs';
|
|
3
|
+
import { T as TranslationKey } from './types-BF48VxkC.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Find and Replace Dialog Component
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunk5UX5CD4C_js=require('./chunk-5UX5CD4C.js');require('./chunk-MKNSJOCN.js'),require('./chunk-NLFXR2VH.js'),require('./chunk-GGQK26JO.js'),require('./chunk-ZXPCJWVY.js'),require('./chunk-
|
|
1
|
+
'use strict';var chunk5UX5CD4C_js=require('./chunk-5UX5CD4C.js');require('./chunk-MKNSJOCN.js'),require('./chunk-NLFXR2VH.js'),require('./chunk-GGQK26JO.js'),require('./chunk-ZXPCJWVY.js'),require('./chunk-ILYKDR3C.js'),require('./chunk-ESZ6JRTW.js'),require('./chunk-H5NTJZO4.js');Object.defineProperty(exports,"PageSetupDialog",{enumerable:true,get:function(){return chunk5UX5CD4C_js.a}});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as PageSetupDialog}from'./chunk-SOTWG3KJ.mjs';import'./chunk-RCIZ7OM3.mjs';import'./chunk-7QQSDIWK.mjs';import'./chunk-B7CCL7SL.mjs';import'./chunk-ONIYA2FU.mjs';import'./chunk-
|
|
1
|
+
export{a as PageSetupDialog}from'./chunk-SOTWG3KJ.mjs';import'./chunk-RCIZ7OM3.mjs';import'./chunk-7QQSDIWK.mjs';import'./chunk-B7CCL7SL.mjs';import'./chunk-ONIYA2FU.mjs';import'./chunk-FWPVBFKQ.mjs';import'./chunk-TZMMD6RR.mjs';import'./chunk-TAUMSKRE.mjs';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { e as PluginHostProps, f as PluginHostRef } from './types-BnIs4sE7.mjs';
|
|
3
|
+
|
|
4
|
+
declare const PLUGIN_HOST_STYLES = "\n.plugin-host {\n display: flex;\n width: 100%;\n height: 100%;\n overflow: visible;\n position: relative;\n}\n\n.plugin-host-editor {\n flex: 1;\n display: flex;\n flex-direction: column;\n min-width: 0;\n overflow: visible;\n}\n\n\n.plugin-panels-left,\n.plugin-panels-right {\n display: flex;\n flex-direction: column;\n flex-shrink: 0;\n background: #f8f9fa;\n border-color: #e9ecef;\n}\n\n.plugin-panels-left {\n border-right: 1px solid #e9ecef;\n}\n\n.plugin-panels-right {\n border-left: 1px solid #e9ecef;\n}\n\n.plugin-panels-bottom {\n border-top: 1px solid #e9ecef;\n background: #f8f9fa;\n}\n\n.plugin-panel {\n position: relative;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n transition: width 0.2s ease, height 0.2s ease;\n}\n\n.plugin-panel.collapsed {\n overflow: visible;\n}\n\n.plugin-panel-toggle {\n display: flex;\n align-items: center;\n gap: 4px;\n padding: 6px 8px;\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n color: #6c757d;\n white-space: nowrap;\n}\n\n.plugin-panel.collapsed .plugin-panel-toggle {\n writing-mode: vertical-rl;\n text-orientation: mixed;\n flex-direction: column;\n height: 100%;\n padding: 8px 6px;\n}\n\n.plugin-panel-toggle:hover {\n background: #e9ecef;\n color: #495057;\n}\n\n.plugin-panel-toggle-icon {\n font-weight: bold;\n font-size: 14px;\n}\n\n.plugin-panel.collapsed .plugin-panel-toggle-icon {\n transform: rotate(90deg);\n}\n\n.plugin-panel-toggle-label {\n font-weight: 500;\n}\n\n.plugin-panel-content {\n flex: 1;\n overflow: auto;\n}\n\n/* Right panel rendered inside viewport - scrolls with content */\n.plugin-panel-in-viewport {\n position: absolute;\n top: 0;\n /* Position is set dynamically via inline styles based on page edge */\n width: 220px;\n pointer-events: auto;\n z-index: 10;\n overflow: visible;\n}\n\n.plugin-panel-in-viewport.collapsed {\n width: 32px;\n}\n\n.plugin-panel-in-viewport .plugin-panel-toggle {\n position: sticky;\n top: 0;\n background: rgba(255, 255, 255, 0.95);\n border-radius: 4px;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n}\n\n.plugin-panel-in-viewport-content {\n overflow: visible;\n position: relative;\n}\n\n/* Plugin overlay container for rendering highlights/decorations */\n.plugin-overlays-container {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n overflow: visible;\n z-index: 5;\n}\n\n.plugin-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n}\n\n/* Individual overlay children manage their own pointer-events.\n Do NOT set pointer-events: auto here \u2014 it overrides overlay containers\n that need pointer-events: none to let clicks pass through to the editor. */\n";
|
|
5
|
+
/**
|
|
6
|
+
* PluginHost Component
|
|
7
|
+
*
|
|
8
|
+
* Wraps the editor and provides:
|
|
9
|
+
* - Plugin state management
|
|
10
|
+
* - Panel rendering for each plugin
|
|
11
|
+
* - CSS injection for plugin styles
|
|
12
|
+
* - Callbacks for editor interaction
|
|
13
|
+
*/
|
|
14
|
+
declare const PluginHost: React.ForwardRefExoticComponent<PluginHostProps & React.RefAttributes<PluginHostRef>>;
|
|
15
|
+
|
|
16
|
+
export { PluginHost as P, PLUGIN_HOST_STYLES as a };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { e as PluginHostProps, f as PluginHostRef } from './types-BnIs4sE7.js';
|
|
3
|
+
|
|
4
|
+
declare const PLUGIN_HOST_STYLES = "\n.plugin-host {\n display: flex;\n width: 100%;\n height: 100%;\n overflow: visible;\n position: relative;\n}\n\n.plugin-host-editor {\n flex: 1;\n display: flex;\n flex-direction: column;\n min-width: 0;\n overflow: visible;\n}\n\n\n.plugin-panels-left,\n.plugin-panels-right {\n display: flex;\n flex-direction: column;\n flex-shrink: 0;\n background: #f8f9fa;\n border-color: #e9ecef;\n}\n\n.plugin-panels-left {\n border-right: 1px solid #e9ecef;\n}\n\n.plugin-panels-right {\n border-left: 1px solid #e9ecef;\n}\n\n.plugin-panels-bottom {\n border-top: 1px solid #e9ecef;\n background: #f8f9fa;\n}\n\n.plugin-panel {\n position: relative;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n transition: width 0.2s ease, height 0.2s ease;\n}\n\n.plugin-panel.collapsed {\n overflow: visible;\n}\n\n.plugin-panel-toggle {\n display: flex;\n align-items: center;\n gap: 4px;\n padding: 6px 8px;\n background: transparent;\n border: none;\n cursor: pointer;\n font-size: 12px;\n color: #6c757d;\n white-space: nowrap;\n}\n\n.plugin-panel.collapsed .plugin-panel-toggle {\n writing-mode: vertical-rl;\n text-orientation: mixed;\n flex-direction: column;\n height: 100%;\n padding: 8px 6px;\n}\n\n.plugin-panel-toggle:hover {\n background: #e9ecef;\n color: #495057;\n}\n\n.plugin-panel-toggle-icon {\n font-weight: bold;\n font-size: 14px;\n}\n\n.plugin-panel.collapsed .plugin-panel-toggle-icon {\n transform: rotate(90deg);\n}\n\n.plugin-panel-toggle-label {\n font-weight: 500;\n}\n\n.plugin-panel-content {\n flex: 1;\n overflow: auto;\n}\n\n/* Right panel rendered inside viewport - scrolls with content */\n.plugin-panel-in-viewport {\n position: absolute;\n top: 0;\n /* Position is set dynamically via inline styles based on page edge */\n width: 220px;\n pointer-events: auto;\n z-index: 10;\n overflow: visible;\n}\n\n.plugin-panel-in-viewport.collapsed {\n width: 32px;\n}\n\n.plugin-panel-in-viewport .plugin-panel-toggle {\n position: sticky;\n top: 0;\n background: rgba(255, 255, 255, 0.95);\n border-radius: 4px;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n}\n\n.plugin-panel-in-viewport-content {\n overflow: visible;\n position: relative;\n}\n\n/* Plugin overlay container for rendering highlights/decorations */\n.plugin-overlays-container {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n overflow: visible;\n z-index: 5;\n}\n\n.plugin-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n pointer-events: none;\n}\n\n/* Individual overlay children manage their own pointer-events.\n Do NOT set pointer-events: auto here \u2014 it overrides overlay containers\n that need pointer-events: none to let clicks pass through to the editor. */\n";
|
|
5
|
+
/**
|
|
6
|
+
* PluginHost Component
|
|
7
|
+
*
|
|
8
|
+
* Wraps the editor and provides:
|
|
9
|
+
* - Plugin state management
|
|
10
|
+
* - Panel rendering for each plugin
|
|
11
|
+
* - CSS injection for plugin styles
|
|
12
|
+
* - Callbacks for editor interaction
|
|
13
|
+
*/
|
|
14
|
+
declare const PluginHost: React.ForwardRefExoticComponent<PluginHostProps & React.RefAttributes<PluginHostRef>>;
|
|
15
|
+
|
|
16
|
+
export { PluginHost as P, PLUGIN_HOST_STYLES as a };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default, { CSSProperties } from 'react';
|
|
2
|
-
import { T as TextFormatting, P as ParagraphFormatting } from './content-
|
|
2
|
+
import { T as TextFormatting, P as ParagraphFormatting } from './content-REFGFfEH.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shared FontOption shape + normaliser used by FontPicker components
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React__default, { CSSProperties } from 'react';
|
|
2
|
-
import { T as TextFormatting, P as ParagraphFormatting } from './content-
|
|
2
|
+
import { T as TextFormatting, P as ParagraphFormatting } from './content-REFGFfEH.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Shared FontOption shape + normaliser used by FontPicker components
|
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var chunkILYKDR3C_js=require('./chunk-ILYKDR3C.js'),chunkH5NTJZO4_js=require('./chunk-H5NTJZO4.js');var k=class{constructor(){chunkH5NTJZO4_js.d(this,"plugins",new Map);chunkH5NTJZO4_js.d(this,"commandHandlers",new Map);chunkH5NTJZO4_js.d(this,"eventListeners",new Set);chunkH5NTJZO4_js.d(this,"initialized",new Set);}register(e,r){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,o]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let s=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${s.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:o});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(o=>{this.emit({type:"error",pluginId:e.id,error:o});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return r?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let r=this.plugins.get(e);if(!r)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(r.destroy)try{let n=r.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let r of this.plugins.values())r.mcpTools&&e.push(...r.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let r of this.plugins.values())if(r.mcpTools){let n=r.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let r of this.eventListeners)try{r(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},v=new k;function H(i,e){let r=v.getCommandHandler(e.type);if(r)return r(i,e);switch(e.type){case "insertText":return $(i,e);case "replaceText":return S(i,e);case "deleteText":return A(i,e);case "formatText":return M(i,e);case "formatParagraph":return B(i,e);case "applyStyle":return V(i,e);case "insertTable":return z(i,e);case "insertImage":return F(i,e);case "insertHyperlink":return L(i,e);case "removeHyperlink":return O(i,e);case "insertParagraphBreak":return R(i,e);case "mergeParagraphs":return j(i,e);case "splitParagraph":return N(i,e);case "setVariable":return _(i,e);case "applyVariables":return J(i,e);default:let n=e;throw new Error(`Unknown command type: ${n.type}`)}}function Q(i,e){return e.reduce((r,n)=>H(r,n),i)}function h(i){return JSON.parse(JSON.stringify(i))}function f(i,e){let r=0;for(let n=0;n<i.content.length;n++)if(i.content[n].type==="paragraph"){if(r===e)return n;r++;}return -1}function I(i){let e="";for(let r of i.content)if(r.type==="run")for(let n of r.content)n.type==="text"&&(e+=n.text);else if(r.type==="hyperlink"){for(let n of r.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function C(i,e){return {type:"run",formatting:e,content:[{type:"text",text:i}]}}function T(i,e,r,n){let t=[],o=0,s=false;for(let a of i.content)if(a.type==="run"){let c=a.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=o,l=o+c.length;if(!s&&e>=p&&e<=l){let u=e-p;u>0&&t.push({...a,content:[{type:"text",text:c.slice(0,u)}]}),t.push(C(r,n||a.formatting)),u<c.length&&t.push({...a,content:[{type:"text",text:c.slice(u)}]}),s=true;}else t.push(a);o=l;}else t.push(a);return s||t.push(C(r,n)),t}function y(i,e,r){let n=[],t=0;for(let o of i.content)if(o.type==="run"){let s=o.content.filter(p=>p.type==="text").map(p=>p.text).join(""),a=t,c=t+s.length;if(c<=e||a>=r)n.push(o);else {let p="";a<e&&(p+=s.slice(0,e-a)),c>r&&(p+=s.slice(r-a)),p.length>0&&n.push({...o,content:[{type:"text",text:p}]});}t=c;}else n.push(o);return n}function E(i,e,r,n){let t=[],o=0;for(let s of i.content)if(s.type==="run"){let a=s.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=o,p=o+a.length;if(p<=e||c>=r)t.push(s);else if(c>=e&&p<=r)t.push({...s,formatting:{...s.formatting,...n}});else {let l=Math.max(e,c),u=Math.min(r,p);c<l&&t.push({...s,content:[{type:"text",text:a.slice(0,l-c)}]}),t.push({...s,formatting:{...s.formatting,...n},content:[{type:"text",text:a.slice(l-c,u-c)}]}),p>u&&t.push({...s,content:[{type:"text",text:a.slice(u-c)}]});}o=p;}else t.push(s);return t}function $(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t];return o.content=T(o,e.position.offset,e.text,e.formatting),r}function S(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=y(a,t.offset,o.offset),a.content=T(a,t.offset,e.text,e.formatting);}else {let s=f(n,t.paragraphIndex),a=n.content[s],c=I(a);a.content=y(a,t.offset,c.length),a.content=T(a,t.offset,e.text,e.formatting);let p=[];for(let l=t.paragraphIndex+1;l<=o.paragraphIndex;l++)p.push(f(n,l));for(let l=p.length-1;l>=0;l--)p[l]!==-1&&n.content.splice(p[l],1);}return r}function A(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=y(a,t.offset,o.offset);}else {let s=f(n,t.paragraphIndex),a=n.content[s],c=I(a);a.content=y(a,t.offset,c.length);let p=f(n,o.paragraphIndex),l=n.content[p];l.content=y(l,0,o.offset),a.content.push(...l.content);let u=[];for(let g=t.paragraphIndex+1;g<=o.paragraphIndex;g++)u.push(f(n,g));for(let g=u.length-1;g>=0;g--)u[g]!==-1&&n.content.splice(u[g],1);}return r}function M(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=E(a,t.offset,o.offset,e.formatting);}else for(let s=t.paragraphIndex;s<=o.paragraphIndex;s++){let a=f(n,s);if(a===-1)continue;let c=n.content[a],p=I(c),l=0,u=p.length;s===t.paragraphIndex&&(l=t.offset),s===o.paragraphIndex&&(u=o.offset),c.content=E(c,l,u,e.formatting);}return r}function B(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t];if(o.formatting={...o.formatting,...e.formatting},"numPr"in e.formatting){let s=e.formatting.numPr;if(s&&s.numId!==void 0&&s.numId!==0){let a=s.ilvl??0,c=s.numId===1,p=c?"\u2022":"1.";if(r.package.numbering){let l=r.package.numbering.nums.find(u=>u.numId===s.numId);if(l){let u=r.package.numbering.abstractNums.find(g=>g.abstractNumId===l.abstractNumId);if(u){let g=u.levels.find(d=>d.ilvl===a);g&&(p=g.lvlText||p);}}}o.listRendering={level:a,numId:s.numId,marker:p,isBullet:c};}else delete o.listRendering;}return r}function V(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t];return o.formatting={...o.formatting,styleId:e.styleId},r}function z(i,e){let r=h(i),n=r.package.document,t=[];for(let a=0;a<e.rows;a++){let c=[];for(let p=0;p<e.columns;p++){let l=e.data?.[a]?.[p]||"";c.push({type:"tableCell",content:[{type:"paragraph",content:l?[C(l)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:c});}let o={type:"table",rows:t},s=f(n,e.position.paragraphIndex);return s===-1?n.content.push(o):n.content.splice(s+1,0,o),r}function F(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:chunkILYKDR3C_js.d(e.width||100),height:chunkILYKDR3C_js.d(e.height||100)},wrap:{type:"inline"}}}]},c=T(o,e.position.offset,"",void 0),p=false,l=0;for(let u=0;u<c.length;u++){let g=c[u];if(g.type==="run"){let d=g.content.filter(m=>m.type==="text").map(m=>m.text).join("");if(l+=d.length,!p&&l>=e.position.offset){c.splice(u+1,0,a),p=true;break}}}return p||c.push(a),o.content=c,r}function L(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex!==o.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s],c=I(a),p=e.displayText||c.slice(t.offset,o.offset);a.content=y(a,t.offset,o.offset);let l={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[C(p)]},u=false,g=0,d=[];for(let m of a.content)if(m.type==="run"){let b=m.content.filter(x=>x.type==="text").map(x=>x.text).join(""),D=g+b.length;if(!u&&g<=t.offset&&t.offset<=D){let x=t.offset-g;x>0&&d.push({...m,content:[{type:"text",text:b.slice(0,x)}]}),d.push(l),x<b.length&&d.push({...m,content:[{type:"text",text:b.slice(x)}]}),u=true;}else d.push(m);g=D;}else d.push(m);return u||d.push(l),a.content=d,r}function O(i,e){let r=h(i),n=r.package.document,{start:t}=e.range,o=f(n,t.paragraphIndex);if(o===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let s=n.content[o],a=[];for(let c of s.content)if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&a.push(p);else a.push(c);return s.content=a,r}function R(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t],s=I(o),a=y({...o,content:[...o.content]},e.position.offset,s.length),c=y({...o,content:[...o.content]},0,e.position.offset);o.content=a;let p={type:"paragraph",formatting:o.formatting,content:c};return n.content.splice(t+1,0,p),r}function j(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t],s=[];for(let a=1;a<=e.count;a++){let c=f(n,e.paragraphIndex+a);if(c!==-1){let p=n.content[c];o.content.push(...p.content),s.push(c);}}for(let a=s.length-1;a>=0;a--)n.content.splice(s[a],1);return r}function N(i,e){return R(i,{position:e.position})}function _(i,e){let r=h(i);return r.templateVariables||(r.templateVariables=[]),r.templateVariables.includes(e.name)||r.templateVariables.push(e.name),r}function J(i,e){let r=h(i),n=r.package.document;function t(a){for(let c of a.content)if(c.type==="text")for(let[p,l]of Object.entries(e.values)){let u=new RegExp(`\\{${p}\\}`,"g");c.text=c.text.replace(u,l);}}function o(a){for(let c of a.content)if(c.type==="run")t(c);else if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&t(p);}function s(a){if(a.type==="paragraph")o(a);else if(a.type==="table")for(let c of a.rows)for(let p of c.cells)for(let l of p.content)s(l);}for(let a of n.content)s(a);return r}exports.a=H;exports.b=Q;
|
|
1
|
+
'use strict';var chunkILYKDR3C_js=require('./chunk-ILYKDR3C.js'),chunkH5NTJZO4_js=require('./chunk-H5NTJZO4.js');var k=class{constructor(){chunkH5NTJZO4_js.d(this,"plugins",new Map);chunkH5NTJZO4_js.d(this,"commandHandlers",new Map);chunkH5NTJZO4_js.d(this,"eventListeners",new Set);chunkH5NTJZO4_js.d(this,"initialized",new Set);}register(e,r){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,o]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let s=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${s.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:o});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(o=>{this.emit({type:"error",pluginId:e.id,error:o});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return r?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let r=this.plugins.get(e);if(!r)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(r.destroy)try{let n=r.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let r of this.plugins.values())r.mcpTools&&e.push(...r.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let r of this.plugins.values())if(r.mcpTools){let n=r.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let r of this.eventListeners)try{r(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},v=new k;function H(i,e){let r=v.getCommandHandler(e.type);if(r)return r(i,e);switch(e.type){case "insertText":return $(i,e);case "replaceText":return S(i,e);case "deleteText":return A(i,e);case "formatText":return M(i,e);case "formatParagraph":return B(i,e);case "applyStyle":return V(i,e);case "insertTable":return z(i,e);case "insertImage":return F(i,e);case "insertHyperlink":return L(i,e);case "removeHyperlink":return O(i,e);case "insertParagraphBreak":return R(i,e);case "mergeParagraphs":return j(i,e);case "splitParagraph":return N(i,e);case "setVariable":return _(i,e);case "applyVariables":return J(i,e);default:let n=e;throw new Error(`Unknown command type: ${n.type}`)}}function Q(i,e){return e.reduce((r,n)=>H(r,n),i)}function h(i){return JSON.parse(JSON.stringify(i))}function f(i,e){let r=0;for(let n=0;n<i.content.length;n++)if(i.content[n].type==="paragraph"){if(r===e)return n;r++;}return -1}function I(i){let e="";for(let r of i.content)if(r.type==="run")for(let n of r.content)n.type==="text"&&(e+=n.text);else if(r.type==="hyperlink"){for(let n of r.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function C(i,e){return {type:"run",formatting:e,content:[{type:"text",text:i}]}}function T(i,e,r,n){let t=[],o=0,s=false;for(let a of i.content)if(a.type==="run"){let c=a.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=o,l=o+c.length;if(!s&&e>=p&&e<=l){let u=e-p;u>0&&t.push({...a,content:[{type:"text",text:c.slice(0,u)}]}),t.push(C(r,n||a.formatting)),u<c.length&&t.push({...a,content:[{type:"text",text:c.slice(u)}]}),s=true;}else t.push(a);o=l;}else t.push(a);return s||t.push(C(r,n)),t}function y(i,e,r){let n=[],t=0;for(let o of i.content)if(o.type==="run"){let s=o.content.filter(p=>p.type==="text").map(p=>p.text).join(""),a=t,c=t+s.length;if(c<=e||a>=r)n.push(o);else {let p="";a<e&&(p+=s.slice(0,e-a)),c>r&&(p+=s.slice(r-a)),p.length>0&&n.push({...o,content:[{type:"text",text:p}]});}t=c;}else n.push(o);return n}function E(i,e,r,n){let t=[],o=0;for(let s of i.content)if(s.type==="run"){let a=s.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=o,p=o+a.length;if(p<=e||c>=r)t.push(s);else if(c>=e&&p<=r)t.push({...s,formatting:{...s.formatting,...n}});else {let l=Math.max(e,c),u=Math.min(r,p);c<l&&t.push({...s,content:[{type:"text",text:a.slice(0,l-c)}]}),t.push({...s,formatting:{...s.formatting,...n},content:[{type:"text",text:a.slice(l-c,u-c)}]}),p>u&&t.push({...s,content:[{type:"text",text:a.slice(u-c)}]});}o=p;}else t.push(s);return t}function $(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t];return o.content=T(o,e.position.offset,e.text,e.formatting),r}function S(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=y(a,t.offset,o.offset),a.content=T(a,t.offset,e.text,e.formatting);}else {let s=f(n,t.paragraphIndex),a=n.content[s],c=I(a);a.content=y(a,t.offset,c.length),a.content=T(a,t.offset,e.text,e.formatting);let p=[];for(let l=t.paragraphIndex+1;l<=o.paragraphIndex;l++)p.push(f(n,l));for(let l=p.length-1;l>=0;l--)p[l]!==-1&&n.content.splice(p[l],1);}return r}function A(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=y(a,t.offset,o.offset);}else {let s=f(n,t.paragraphIndex),a=n.content[s],c=I(a);a.content=y(a,t.offset,c.length);let p=f(n,o.paragraphIndex),l=n.content[p];l.content=y(l,0,o.offset),a.content.push(...l.content);let u=[];for(let g=t.paragraphIndex+1;g<=o.paragraphIndex;g++)u.push(f(n,g));for(let g=u.length-1;g>=0;g--)u[g]!==-1&&n.content.splice(u[g],1);}return r}function M(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex===o.paragraphIndex){let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s];a.content=E(a,t.offset,o.offset,e.formatting);}else for(let s=t.paragraphIndex;s<=o.paragraphIndex;s++){let a=f(n,s);if(a===-1)continue;let c=n.content[a],p=I(c),l=0,u=p.length;s===t.paragraphIndex&&(l=t.offset),s===o.paragraphIndex&&(u=o.offset),c.content=E(c,l,u,e.formatting);}return r}function B(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t];if(o.formatting={...o.formatting,...e.formatting},"numPr"in e.formatting){let s=e.formatting.numPr;if(s&&s.numId!==void 0&&s.numId!==0){let a=s.ilvl??0,c=s.numId===1,p=c?"\u2022":"1.";if(r.package.numbering){let l=r.package.numbering.nums.find(u=>u.numId===s.numId);if(l){let u=r.package.numbering.abstractNums.find(g=>g.abstractNumId===l.abstractNumId);if(u){let g=u.levels.find(d=>d.ilvl===a);g&&(p=g.lvlText||p);}}}o.listRendering={level:a,numId:s.numId,marker:p,isBullet:c};}else delete o.listRendering;}return r}function V(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t];return o.formatting={...o.formatting,styleId:e.styleId},r}function z(i,e){let r=h(i),n=r.package.document,t=[];for(let a=0;a<e.rows;a++){let c=[];for(let p=0;p<e.columns;p++){let l=e.data?.[a]?.[p]||"";c.push({type:"tableCell",content:[{type:"paragraph",content:l?[C(l)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:c});}let o={type:"table",rows:t},s=f(n,e.position.paragraphIndex);return s===-1?n.content.push(o):n.content.splice(s+1,0,o),r}function F(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:chunkILYKDR3C_js.d(e.width||100),height:chunkILYKDR3C_js.d(e.height||100)},wrap:{type:"inline"}}}]},c=T(o,e.position.offset,"",void 0),p=false,l=0;for(let u=0;u<c.length;u++){let g=c[u];if(g.type==="run"){let d=g.content.filter(m=>m.type==="text").map(m=>m.text).join("");if(l+=d.length,!p&&l>=e.position.offset){c.splice(u+1,0,a),p=true;break}}}return p||c.push(a),o.content=c,r}function L(i,e){let r=h(i),n=r.package.document,{start:t,end:o}=e.range;if(t.paragraphIndex!==o.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let s=f(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[s],c=I(a),p=e.displayText||c.slice(t.offset,o.offset);a.content=y(a,t.offset,o.offset);let l={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[C(p)]},u=false,g=0,d=[];for(let m of a.content)if(m.type==="run"){let b=m.content.filter(x=>x.type==="text").map(x=>x.text).join(""),D=g+b.length;if(!u&&g<=t.offset&&t.offset<=D){let x=t.offset-g;x>0&&d.push({...m,content:[{type:"text",text:b.slice(0,x)}]}),d.push(l),x<b.length&&d.push({...m,content:[{type:"text",text:b.slice(x)}]}),u=true;}else d.push(m);g=D;}else d.push(m);return u||d.push(l),a.content=d,r}function O(i,e){let r=h(i),n=r.package.document,{start:t}=e.range,o=f(n,t.paragraphIndex);if(o===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let s=n.content[o],a=[];for(let c of s.content)if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&a.push(p);else a.push(c);return s.content=a,r}function R(i,e){let r=h(i),n=r.package.document,t=f(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let o=n.content[t],s=I(o),a=y({...o,content:[...o.content]},e.position.offset,s.length),c=y({...o,content:[...o.content]},0,e.position.offset);o.content=a;let p={type:"paragraph",formatting:o.formatting,content:c};return n.content.splice(t+1,0,p),r}function j(i,e){let r=h(i),n=r.package.document,t=f(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let o=n.content[t],s=[];for(let a=1;a<=e.count;a++){let c=f(n,e.paragraphIndex+a);if(c!==-1){let p=n.content[c];o.content.push(...p.content),s.push(c);}}for(let a=s.length-1;a>=0;a--)n.content.splice(s[a],1);return r}function N(i,e){return R(i,{position:e.position})}function _(i,e){let r=h(i);return r.templateVariables||(r.templateVariables=[]),r.templateVariables.includes(e.name)||r.templateVariables.push(e.name),r}function J(i,e){let r=h(i),n=r.package.document;function t(a){for(let c of a.content)if(c.type==="text")for(let[p,l]of Object.entries(e.values)){let u=new RegExp(`\\{${p}\\}`,"g");c.text=c.text.replace(u,l);}}function o(a){for(let c of a.content)if(c.type==="run")t(c);else if(c.type==="hyperlink")for(let p of c.children)p.type==="run"&&t(p);}function s(a){if(a.type==="paragraph")o(a);else if(a.type==="table")for(let c of a.rows)for(let p of c.cells)for(let l of p.content)s(l);}for(let a of n.content)s(a);return r}exports.a=v;exports.b=H;exports.c=Q;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import {s,r}from'./chunk-MDTA25AN.mjs';import me,{forwardRef,useState,useRef,useMemo,useSyncExternalStore,useEffect,useCallback,useImperativeHandle,cloneElement}from'react';import {TextSelection,PluginKey,Plugin}from'prosemirror-state';import {jsx,jsxs}from'react/jsx-runtime';import {DecorationSet,Decoration}from'prosemirror-view';var $={position:"right",defaultSize:280,minSize:200,maxSize:500,resizable:true,collapsible:true,defaultCollapsed:false},te=r,ne=`
|
|
2
|
+
.plugin-host {
|
|
3
|
+
display: flex;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
overflow: visible;
|
|
7
|
+
position: relative;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.plugin-host-editor {
|
|
11
|
+
flex: 1;
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
overflow: visible;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
.plugin-panels-left,
|
|
20
|
+
.plugin-panels-right {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: column;
|
|
23
|
+
flex-shrink: 0;
|
|
24
|
+
background: #f8f9fa;
|
|
25
|
+
border-color: #e9ecef;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.plugin-panels-left {
|
|
29
|
+
border-right: 1px solid #e9ecef;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.plugin-panels-right {
|
|
33
|
+
border-left: 1px solid #e9ecef;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.plugin-panels-bottom {
|
|
37
|
+
border-top: 1px solid #e9ecef;
|
|
38
|
+
background: #f8f9fa;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.plugin-panel {
|
|
42
|
+
position: relative;
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
transition: width 0.2s ease, height 0.2s ease;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.plugin-panel.collapsed {
|
|
50
|
+
overflow: visible;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.plugin-panel-toggle {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: 4px;
|
|
57
|
+
padding: 6px 8px;
|
|
58
|
+
background: transparent;
|
|
59
|
+
border: none;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
color: #6c757d;
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.plugin-panel.collapsed .plugin-panel-toggle {
|
|
67
|
+
writing-mode: vertical-rl;
|
|
68
|
+
text-orientation: mixed;
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
height: 100%;
|
|
71
|
+
padding: 8px 6px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.plugin-panel-toggle:hover {
|
|
75
|
+
background: #e9ecef;
|
|
76
|
+
color: #495057;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.plugin-panel-toggle-icon {
|
|
80
|
+
font-weight: bold;
|
|
81
|
+
font-size: 14px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.plugin-panel.collapsed .plugin-panel-toggle-icon {
|
|
85
|
+
transform: rotate(90deg);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.plugin-panel-toggle-label {
|
|
89
|
+
font-weight: 500;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.plugin-panel-content {
|
|
93
|
+
flex: 1;
|
|
94
|
+
overflow: auto;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* Right panel rendered inside viewport - scrolls with content */
|
|
98
|
+
.plugin-panel-in-viewport {
|
|
99
|
+
position: absolute;
|
|
100
|
+
top: 0;
|
|
101
|
+
/* Position is set dynamically via inline styles based on page edge */
|
|
102
|
+
width: 220px;
|
|
103
|
+
pointer-events: auto;
|
|
104
|
+
z-index: 10;
|
|
105
|
+
overflow: visible;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.plugin-panel-in-viewport.collapsed {
|
|
109
|
+
width: 32px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.plugin-panel-in-viewport .plugin-panel-toggle {
|
|
113
|
+
position: sticky;
|
|
114
|
+
top: 0;
|
|
115
|
+
background: rgba(255, 255, 255, 0.95);
|
|
116
|
+
border-radius: 4px;
|
|
117
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.plugin-panel-in-viewport-content {
|
|
121
|
+
overflow: visible;
|
|
122
|
+
position: relative;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Plugin overlay container for rendering highlights/decorations */
|
|
126
|
+
.plugin-overlays-container {
|
|
127
|
+
position: absolute;
|
|
128
|
+
top: 0;
|
|
129
|
+
left: 0;
|
|
130
|
+
right: 0;
|
|
131
|
+
bottom: 0;
|
|
132
|
+
pointer-events: none;
|
|
133
|
+
overflow: visible;
|
|
134
|
+
z-index: 5;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.plugin-overlay {
|
|
138
|
+
position: absolute;
|
|
139
|
+
top: 0;
|
|
140
|
+
left: 0;
|
|
141
|
+
right: 0;
|
|
142
|
+
bottom: 0;
|
|
143
|
+
pointer-events: none;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Individual overlay children manage their own pointer-events.
|
|
147
|
+
Do NOT set pointer-events: auto here \u2014 it overrides overlay containers
|
|
148
|
+
that need pointer-events: none to let clicks pass through to the editor. */
|
|
149
|
+
`,Ee=forwardRef(function({plugins:i,children:s$1,className:r=""},p){let[t,f]=useState(null),m=useRef(s$1.props);m.current=s$1.props;let[a,u]=useState(null),l=useMemo(()=>new s,[]),x=useSyncExternalStore(l.subscribe,l.getSnapshot),[T,h]=useState(()=>{let o=new Set;for(let e of i)({...$,...e.panelConfig}).defaultCollapsed&&o.add(e.id);return o}),[v]=useState(()=>{let o=new Map;for(let e of i){let d={...$,...e.panelConfig};o.set(e.id,d.defaultSize);}return o});useEffect(()=>{if(!t)return;let o=i.map(e=>({id:e.id,styles:e.styles,initialize:e.initialize,onStateChange:e.onStateChange,destroy:e.destroy}));return l.initialize(o,t),()=>{l.destroy();}},[l,t,i]),useEffect(()=>{let o=i.filter(e=>e.styles).map(e=>te(e.id,e.styles));return ()=>o.forEach(e=>e())},[i]),useEffect(()=>{if(!t?.dom)return;let o=()=>{l.updateStates(t);},e=null,d=()=>{e&&cancelAnimationFrame(e),e=requestAnimationFrame(o);};o();let c=t.dom;c.addEventListener("input",d),c.addEventListener("focus",o),c.addEventListener("click",o);let g=t.dispatch.bind(t);return t.dispatch=y=>{g(y),d();},()=>{c.removeEventListener("input",d),c.removeEventListener("focus",o),c.removeEventListener("click",o),e&&cancelAnimationFrame(e),t.dispatch=g;}},[t,l]),useEffect(()=>te("plugin-host-base",ne),[]);let R=useCallback(o=>{if(!t)return;if(t.coordsAtPos(o)){t.dom.scrollIntoView({block:"center",inline:"nearest"});let{state:d}=t,c=d.doc.resolve(Math.min(o,d.doc.content.size)),g=d.tr.setSelection(TextSelection.near(c));t.dispatch(g),t.focus();}},[t]),P=useCallback((o,e)=>{if(!t)return;let{state:d}=t,c=d.doc.content.size,g=Math.max(0,Math.min(o,c)),y=Math.max(0,Math.min(e,c)),L=d.tr.setSelection(TextSelection.create(d.doc,g,y));t.dispatch(L),t.focus();},[t]),E=useCallback(o=>l.getPluginState(o),[l]),K=useCallback((o,e)=>{l.setPluginState(o,e);},[l]),U=useCallback(()=>{t&&l.updateStates(t);},[t,l]);useImperativeHandle(p,()=>({getPluginState:E,setPluginState:K,getEditorView:()=>t,refreshPluginStates:U}),[E,K,t,U]);let W=useMemo(()=>{let o=[];for(let e of i)e.proseMirrorPlugins&&o.push(...e.proseMirrorPlugins);return o},[i]),_=useCallback(o=>{h(e=>{let d=new Set(e);return d.has(o)?d.delete(o):d.add(o),d});},[]),[A,F]=useState(null);useEffect(()=>{if(!a){F(null);return}let o=()=>{let c=a.pagesContainer,g=c.querySelector(".layout-page");if(!g){F(null);return}let y=a.getContainerOffset(),L=g.getBoundingClientRect(),Y=c.getBoundingClientRect(),G=(L.right-Y.left)/a.zoom,xe=y.x+G+5;F(xe);};o();let e=()=>{requestAnimationFrame(o);};window.addEventListener("resize",e);let d=new ResizeObserver(()=>{requestAnimationFrame(o);});return d.observe(a.pagesContainer),()=>{window.removeEventListener("resize",e),d.disconnect();}},[a]);let Z=useMemo(()=>{let o=[];if(a){for(let e of i)if(e.renderOverlay){let d=x.states.get(e.id);o.push(jsx("div",{className:"plugin-overlay","data-plugin-id":e.id,children:e.renderOverlay(a,d,t)},`overlay-${e.id}`));}}for(let e of i){if(!e.Panel||(e.panelConfig?.position??"right")!=="right")continue;let c={...$,...e.panelConfig},g=T.has(e.id),y=v.get(e.id)??c.defaultSize,L=e.Panel,Y=x.states.get(e.id),G=A!==null?`${A}px`:"calc(50% + 428px)";o.push(jsxs("div",{className:`plugin-panel-in-viewport ${g?"collapsed":""}`,style:{width:g?"32px":`${y}px`,left:G},"data-plugin-id":e.id,children:[c.collapsible&&jsx("button",{className:"plugin-panel-toggle",onClick:()=>_(e.id),title:g?`Show ${e.name}`:`Hide ${e.name}`,"aria-label":g?`Show ${e.name}`:`Hide ${e.name}`,children:jsx("span",{className:"plugin-panel-toggle-icon",children:g?"\u2039":"\u203A"})}),!g&&a&&jsx("div",{className:"plugin-panel-in-viewport-content",children:jsx(L,{editorView:t,doc:t?.state.doc??null,scrollToPosition:R,selectRange:P,pluginState:Y,panelWidth:y,renderedDomContext:a})})]},`panel-overlay-${e.id}`));}return o.length>0?o:null},[a,i,x.version,t,T,v,R,P,_,A]),j=useMemo(()=>{let o=[];for(let e of i){if(!e.getSidebarItems)continue;let d=x.states.get(e.id),c={editorView:t,renderedDomContext:a,anchorPositions:new Map,zoom:a?.zoom??1},g=e.getSidebarItems(d,c);o.push(...g);}return o},[i,x.version,t,a]),B=useCallback(o=>{u(o);let e=m.current?.onRenderedDomContextReady;typeof e=="function"&&e(o);},[]),be=useMemo(()=>cloneElement(s$1,{externalPlugins:W,pluginOverlays:Z,pluginSidebarItems:j,pluginRenderedDomContext:a,onRenderedDomContextReady:B,onEditorViewReady:o=>{f(o);let e=m.current?.onEditorViewReady;typeof e=="function"&&e(o);}}),[s$1,W,Z,j,a,B]),O=useMemo(()=>{let o=[],e=[],d=[];for(let c of i){if(!c.Panel)continue;let g=c.panelConfig?.position??"right";g==="left"?o.push(c):g==="bottom"?d.push(c):e.push(c);}return {left:o,right:e,bottom:d}},[i]),X=o=>{if(!o.Panel)return null;let e={...$,...o.panelConfig},d=T.has(o.id),c=v.get(o.id)??e.defaultSize,g=o.Panel,y=x.states.get(o.id);return jsxs("div",{className:`plugin-panel plugin-panel-${e.position} ${d?"collapsed":""}`,style:{[e.position==="bottom"?"height":"width"]:d?"32px":`${c}px`,minWidth:e.position!=="bottom"?d?"32px":`${e.minSize}px`:void 0,maxWidth:e.position!=="bottom"?`${e.maxSize}px`:void 0,minHeight:e.position==="bottom"?d?"32px":`${e.minSize}px`:void 0,maxHeight:e.position==="bottom"?`${e.maxSize}px`:void 0},"data-plugin-id":o.id,children:[e.collapsible&&jsxs("button",{className:"plugin-panel-toggle",onClick:()=>_(o.id),title:d?`Show ${o.name}`:`Hide ${o.name}`,"aria-label":d?`Show ${o.name}`:`Hide ${o.name}`,children:[jsx("span",{className:"plugin-panel-toggle-icon",children:d?"\u203A":"\u2039"}),d&&jsx("span",{className:"plugin-panel-toggle-label",children:o.name})]}),!d&&jsx("div",{className:"plugin-panel-content",children:jsx(g,{editorView:t,doc:t?.state.doc??null,scrollToPosition:R,selectRange:P,pluginState:y,panelWidth:c,renderedDomContext:a??null})})]},o.id)};return jsxs("div",{className:`plugin-host ${r}`,children:[O.left.length>0&&jsx("div",{className:"plugin-panels-left",children:O.left.map(X)}),jsxs("div",{className:"plugin-host-editor",children:[be,O.bottom.length>0&&jsx("div",{className:"plugin-panels-bottom",children:O.bottom.map(X)})]})]})});var oe=/\{([#/^@]?)([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)\}/g,b=new PluginKey("template");function Ce(n,i,s){return `${n}:${i}:${s}`}function ie(n){let i=[];n.descendants((a,u)=>(a.isText&&a.text&&i.push({text:a.text,pos:u}),true));let s="",r=[];for(let a of i){for(let u=0;u<a.text.length;u++)r.push(a.pos+u);s+=a.text;}let p=[],t=[],f=new Map,m;for(oe.lastIndex=0;(m=oe.exec(s))!==null;){let[a,u,l]=m,x=r[m.index],T=r[m.index+a.length-1]+1,h;u==="#"?h="sectionStart":u==="/"?h="sectionEnd":u==="^"?h="invertedStart":u==="@"?h="raw":h="variable";let v=`${h}:${l}`,R=f.get(v)??0;f.set(v,R+1);let P={id:Ce(h,l,R),type:h,name:l,rawTag:a,from:x,to:T};if(h==="sectionStart"||h==="invertedStart")P.nestedVars=[],t.push(P);else if(h==="sectionEnd"){for(let E=t.length-1;E>=0;E--)if(t[E].name===l){t.splice(E,1);break}}else h==="variable"&&t.length>0&&(t[t.length-1].nestedVars?.push(l),P.insideSection=true);p.push(P);}return p}function Le(n){switch(n){case "sectionStart":case "sectionEnd":return "#3b82f6";case "invertedStart":return "#8b5cf6";case "raw":return "#ef4444";default:return "#f59e0b"}}function q(n,i,s,r){let p=[];for(let t of i){let f=t.id===s,m=t.id===r,a=Le(t.type),u=["docx-template-tag"];f&&u.push("hovered"),m&&u.push("selected"),p.push(Decoration.inline(t.from,t.to,{class:u.join(" "),"data-tag-id":t.id,style:`background-color: ${a}22; border-radius: 2px;`},{noOverlay:true}));}return DecorationSet.create(n,p)}function He(n,i){if(n.length!==i.length)return false;for(let s=0;s<n.length;s++)if(n[s].id!==i[s].id)return false;return true}function N(){return new Plugin({key:b,state:{init(n,i){let s=ie(i.doc);return {tags:s,decorations:q(i.doc,s)}},apply(n,i,s,r){if(n.docChanged){let t=ie(r.doc),f=He(i.tags,t);return {tags:t,decorations:f?i.decorations.map(n.mapping,n.doc):q(r.doc,t,i.hoveredId,i.selectedId),hoveredId:i.hoveredId,selectedId:i.selectedId}}let p=n.getMeta(b);if(p){let t=p.hoveredId??i.hoveredId,f=p.selectedId??i.selectedId;return {...i,hoveredId:t,selectedId:f,decorations:q(r.doc,i.tags,t,f)}}return {...i,decorations:i.decorations.map(n.mapping,n.doc)}}},props:{decorations(n){return b.getState(n)?.decorations??DecorationSet.empty},handleClick(n,i){let r=(b.getState(n.state)?.tags??[]).find(t=>i>=t.from&&i<=t.to);return r?(n.dispatch(n.state.tr.setMeta(b,{selectedId:r.id})),true):(b.getState(n.state)?.selectedId&&n.dispatch(n.state.tr.setMeta(b,{selectedId:void 0})),false)},handleDOMEvents:{mouseover(n,i){let r=i.target.closest?.("[data-tag-id]")?.getAttribute("data-tag-id")||void 0,p=b.getState(n.state)?.hoveredId;return r!==p&&n.dispatch(n.state.tr.setMeta(b,{hoveredId:r})),false},mouseout(n,i){return i.relatedTarget?.closest?.("[data-tag-id]")||b.getState(n.state)?.hoveredId&&n.dispatch(n.state.tr.setMeta(b,{hoveredId:void 0})),false}}}})}function ae(n){return b.getState(n)?.tags??[]}function z(n,i){n.dispatch(n.state.tr.setMeta(b,{hoveredId:i}));}function D(n,i){n.dispatch(n.state.tr.setMeta(b,{selectedId:i}));}var V=`
|
|
150
|
+
.docx-template-tag {
|
|
151
|
+
cursor: pointer;
|
|
152
|
+
transition: background-color 0.1s;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.docx-template-tag:hover,
|
|
156
|
+
.docx-template-tag.hovered {
|
|
157
|
+
filter: brightness(0.95);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.docx-template-tag.selected {
|
|
161
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
|
|
162
|
+
}
|
|
163
|
+
`;var Oe={variable:"rgba(245, 158, 11, 0.3)",sectionStart:"rgba(59, 130, 246, 0.3)",sectionEnd:"rgba(59, 130, 246, 0.3)",invertedStart:"rgba(139, 92, 246, 0.3)",raw:"rgba(239, 68, 68, 0.3)"},$e={variable:"rgba(245, 158, 11, 0.5)",sectionStart:"rgba(59, 130, 246, 0.5)",sectionEnd:"rgba(59, 130, 246, 0.5)",invertedStart:"rgba(139, 92, 246, 0.5)",raw:"rgba(239, 68, 68, 0.5)"};function de({context:n,tags:i,hoveredId:s,selectedId:r,onHover:p,onSelect:t}){let[f,m]=useState(0),a=useCallback(()=>{let l=n.getContainerOffset(),x=[];for(let T of i){let h=n.getRectsForRange(T.from,T.to);for(let v of h)x.push({tagId:T.id,tagType:T.type,x:v.x+l.x,y:v.y+l.y,width:v.width,height:v.height});}return x},[n,i]),u=useMemo(()=>a(),[a,f]);return useEffect(()=>{let l=()=>{requestAnimationFrame(()=>m(x=>x+1));};return window.addEventListener("resize",l),()=>window.removeEventListener("resize",l)},[]),useEffect(()=>{let l=new ResizeObserver(()=>{requestAnimationFrame(()=>m(x=>x+1));});return l.observe(n.pagesContainer),()=>l.disconnect()},[n.pagesContainer]),u.length===0?null:jsx("div",{className:"template-highlight-overlay",children:u.map((l,x)=>{let T=l.tagId===s,h=l.tagId===r,v=T||h?$e[l.tagType]:Oe[l.tagType];return jsx("div",{className:`template-highlight ${T?"hovered":""} ${h?"selected":""}`,style:{position:"absolute",left:l.x,top:l.y,width:l.width,height:l.height,backgroundColor:v,borderRadius:2,cursor:"pointer"},onMouseEnter:()=>p?.(l.tagId),onMouseLeave:()=>p?.(void 0),onClick:()=>t?.(l.tagId)},`${l.tagId}-${x}`)})})}var pe=`
|
|
164
|
+
.template-highlight-overlay {
|
|
165
|
+
position: absolute;
|
|
166
|
+
top: 0;
|
|
167
|
+
left: 0;
|
|
168
|
+
right: 0;
|
|
169
|
+
bottom: 0;
|
|
170
|
+
pointer-events: none;
|
|
171
|
+
overflow: visible;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.template-highlight {
|
|
175
|
+
pointer-events: auto;
|
|
176
|
+
transition: background-color 0.1s ease;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.template-highlight:hover,
|
|
180
|
+
.template-highlight.hovered {
|
|
181
|
+
filter: brightness(0.9);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.template-highlight.selected {
|
|
185
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.6);
|
|
186
|
+
}
|
|
187
|
+
`;var Ne={variable:"#f59e0b",sectionStart:"#3b82f6",sectionEnd:"#3b82f6",invertedStart:"#8b5cf6",raw:"#ef4444"};function De(n){switch(n){case "sectionStart":return "LOOP / IF";case "invertedStart":return "IF NOT";case "raw":return "HTML";default:return ""}}var ge=`
|
|
188
|
+
.template-annotation-chip {
|
|
189
|
+
display: inline-flex;
|
|
190
|
+
flex-wrap: wrap;
|
|
191
|
+
align-items: center;
|
|
192
|
+
gap: 4px;
|
|
193
|
+
padding: 5px 10px;
|
|
194
|
+
background: white;
|
|
195
|
+
border: 1px solid #e2e8f0;
|
|
196
|
+
border-left: 3px solid #6c757d;
|
|
197
|
+
border-radius: 4px;
|
|
198
|
+
font-size: 11px;
|
|
199
|
+
cursor: pointer;
|
|
200
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
|
|
201
|
+
max-width: 200px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.template-annotation-chip:hover,
|
|
205
|
+
.template-annotation-chip.hovered {
|
|
206
|
+
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
|
|
207
|
+
border-color: #cbd5e1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.template-annotation-chip.selected {
|
|
211
|
+
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.template-chip-badge {
|
|
215
|
+
font-size: 9px;
|
|
216
|
+
font-weight: 600;
|
|
217
|
+
padding: 1px 5px;
|
|
218
|
+
border-radius: 3px;
|
|
219
|
+
color: white;
|
|
220
|
+
text-transform: uppercase;
|
|
221
|
+
letter-spacing: 0.3px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.template-chip-dot {
|
|
225
|
+
font-size: 8px;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.template-chip-name {
|
|
229
|
+
color: #334155;
|
|
230
|
+
font-weight: 500;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.template-chip-nested {
|
|
234
|
+
display: flex;
|
|
235
|
+
flex-wrap: wrap;
|
|
236
|
+
gap: 4px;
|
|
237
|
+
width: 100%;
|
|
238
|
+
margin-top: 4px;
|
|
239
|
+
padding-top: 4px;
|
|
240
|
+
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.template-nested-var {
|
|
244
|
+
font-size: 10px;
|
|
245
|
+
color: #64748b;
|
|
246
|
+
background: rgba(0, 0, 0, 0.04);
|
|
247
|
+
padding: 2px 6px;
|
|
248
|
+
border-radius: 3px;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
.template-nested-var:hover {
|
|
252
|
+
background: rgba(59, 130, 246, 0.15);
|
|
253
|
+
color: #1e40af;
|
|
254
|
+
}
|
|
255
|
+
`;function ue({tag:n,isHovered:i,measureRef:s,onHover:r,onSelect:p}){let t=De(n.type),f=Ne[n.type],m=n.type==="sectionStart"||n.type==="invertedStart";return jsxs("div",{ref:s,style:{display:"flex",alignItems:"flex-start"},children:[jsx("div",{style:{width:20,height:1,background:i?"#3b82f6":"#d0d0d0",marginTop:12,marginRight:4,flexShrink:0}}),jsxs("div",{className:`template-annotation-chip ${i?"hovered":""}`,style:{borderLeftColor:f},onMouseEnter:()=>r(n.id),onMouseLeave:()=>r(void 0),onClick:a=>{a.stopPropagation(),p(n.id);},onMouseDown:a=>a.stopPropagation(),title:m?`${n.rawTag}
|
|
256
|
+
Iterates over ${n.name}[]. Access nested properties via ${n.name}.property`:n.rawTag,children:[t&&jsx("span",{className:"template-chip-badge",style:{background:f},children:t}),!t&&jsx("span",{className:"template-chip-dot",style:{color:f},children:"\u25CF"}),jsx("span",{className:"template-chip-name",children:n.name}),m&&n.nestedVars&&n.nestedVars.length>0&&jsx("div",{className:"template-chip-nested",children:n.nestedVars.map((a,u)=>jsx("span",{className:"template-nested-var",title:`Access: ${n.name}.${a}`,children:a.includes(".")?a.split(".").pop():a},u))})]})]})}function fe(n,i,s){if(!n)return;D(n,s);let r=i.find(p=>p.id===s);if(r){let p=n.state.tr.setSelection(TextSelection.near(n.state.doc.resolve(r.from)));n.dispatch(p),n.focus();}}function he(n={}){return {id:"template",name:"Template",proseMirrorPlugins:[N()],onStateChange:s=>{let r=b.getState(s.state);if(r)return {tags:r.tags,hoveredId:r.hoveredId,selectedId:r.selectedId}},initialize:s=>({tags:[]}),getSidebarItems:(s,r)=>!s||s.tags.length===0?[]:s.tags.filter(t=>t.type!=="sectionEnd"&&!t.insideSection).map(t=>({id:`template-${t.id}`,anchorPos:t.from,priority:10,estimatedHeight:32,render:f=>me.createElement(ue,{...f,tag:t,isHovered:t.id===s.hoveredId,onHover:m=>{r.editorView&&z(r.editorView,m);},onSelect:m=>fe(r.editorView,s.tags,m)})})),renderOverlay:(s,r,p)=>!r||r.tags.length===0?null:me.createElement(de,{context:s,tags:r.tags,hoveredId:r.hoveredId,selectedId:r.selectedId,onHover:t=>{p&&z(p,t);},onSelect:t=>fe(p,r.tags,t)}),styles:`
|
|
257
|
+
${V}
|
|
258
|
+
${ge}
|
|
259
|
+
${pe}
|
|
260
|
+
`}}var _e=he();export{ne as a,Ee as b,b as c,N as d,ae as e,z as f,D as g,V as h,he as i,_e as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {e,h,i,n as n$1,f,m as m$1,k as k$1,l as l$1,j}from'./chunk-U7ZW2DOO.mjs';import {n,k,l,m}from'./chunk-47VJOBJD.mjs';import {Ha}from'./chunk-XQZTWWRF.mjs';import {d}from'./chunk-TAUMSKRE.mjs';import {useMemo,useState,useCallback,useRef,useEffect}from'react';import {TextSelection}from'prosemirror-state';function gt({document:o,onChange:r,onSelectionChange:a}){let m$2=useMemo(()=>new n,[]),[t,S]=useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=useCallback((l,n,e$1)=>{if(!o)return;let u=k(o,l);if(!u){m$2.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m$2.selectCell({tableIndex:l,rowIndex:n,columnIndex:e$1});let y=e(u,{tableIndex:l,rowIndex:n,columnIndex:e$1});S({context:y,table:u,tableIndex:l,rowIndex:n,columnIndex:e$1}),a?.(y);},[o,m$2,a]),b=useCallback(()=>{m$2.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),a?.(null);},[m$2,a]),i$1=useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:h(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f$1=useCallback((l$1,n)=>{if(!o||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e=i(t.table,t.rowIndex,t.columnIndex,l$1,n);if(e===t.table)return;let u=l(o,t.tableIndex,e);r?.(u),u&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[o,x,r,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),d=useCallback(l$2=>{if(!o||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=t.table;if(!n)return;let e=null,u=null,c=t.rowIndex,y=t.columnIndex;switch(l$2){case "addRowAbove":e=j(n,t.rowIndex,"before"),c=t.rowIndex+1;break;case "addRowBelow":e=j(n,t.rowIndex,"after");break;case "addColumnLeft":e=l$1(n,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":e=l$1(n,t.columnIndex,"after");break;case "deleteRow":n.rows.length>1&&(e=k$1(n,t.rowIndex),c>=e.rows.length&&(c=e.rows.length-1));break;case "deleteColumn":{if(f(n)>1){e=m$1(n,t.columnIndex);let p=f(e);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(e=n$1(n,t.context.selection));break;case "splitCell":break;case "deleteTable":u=m(o,t.tableIndex),b(),r?.(u);return}e&&(u=l(o,t.tableIndex,e),r?.(u),u&&x(t.tableIndex,c,y));},[o,t,r,b,x]),s=useCallback((l,n,e)=>m$2.isCellSelected(l,n,e),[m$2,t]);return {state:t,handleCellClick:x,handleAction:d,getSplitCellConfig:i$1,applySplitCell:f$1,clearSelection:b,isCellSelected:s,tableContext:t.context}}function lt(o,r){return JSON.stringify(o)===JSON.stringify(r)}function at(o,r={}){let{maxEntries:a=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=lt,onUndo:x,onRedo:b,containerRef:i}=r,[f,d]=useState(o),[s,l]=useState([]),[n,e]=useState([]),u=useRef(0),c=useRef(false),y=useCallback((h,g)=>{if(S(f,h))return;if(c.current){d(h);return}let T=Date.now();T-u.current<m&&s.length>0?l(V=>{let A=[...V];return A[A.length-1]={state:f,timestamp:T,description:g||A[A.length-1].description},A}):l(V=>{let A={state:f,timestamp:T,description:g},v=[...V,A];return v.length>a?v.slice(v.length-a):v}),e([]),d(h),u.current=T;},[f,S,m,a,s.length]),E=useCallback(()=>{if(s.length===0)return;c.current=true;let h=s[s.length-1];return l(g=>g.slice(0,-1)),e(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),x?.(h.state),h.state},[s,f,x]),p=useCallback(()=>{if(n.length===0)return;c.current=true;let h=n[n.length-1];return e(g=>g.slice(0,-1)),l(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),b?.(h.state),h.state},[n,f,b]),L=useCallback(()=>{l([]),e([]);},[]),w=useCallback(h=>{d(h??o),l([]),e([]),u.current=0;},[o]),M=useCallback(()=>[...s],[s]),k=useCallback(()=>[...n],[n]),H=useCallback(h=>{d(g=>h(g)),l(g=>g.map(T=>({...T,state:h(T.state)}))),e(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=i?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,i]),{state:f,canUndo:s.length>0,canRedo:n.length>0,undoCount:s.length,redoCount:n.length,push:y,undo:E,redo:p,clear:L,reset:w,getUndoStack:M,getRedoStack:k,transformAll:H}}function Et(o,r={}){let a=at(o,r);return useEffect(()=>{a.push(o);},[o]),a}function wt(o,r={}){let a=useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return at(o,{...r,isEqual:a})}var rt=class{constructor(r,a={}){d(this,"undoStack",[]);d(this,"redoStack",[]);d(this,"currentState");d(this,"maxEntries");d(this,"groupingInterval");d(this,"lastPushTime",0);d(this,"isEqual");this.currentState=r,this.maxEntries=a.maxEntries??100,this.groupingInterval=a.groupingInterval??500,this.isEqual=a.isEqual??lt;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(r,a){if(this.isEqual(this.currentState,r))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:a}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=r,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let r=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=r.state,r.state}redo(){if(this.redoStack.length===0)return;let r=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=r.state,r.state}clear(){this.undoStack=[],this.redoStack=[];}reset(r){this.currentState=r??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};function N(o){let r=o.parentElement;for(;r&&r!==document.documentElement;){let{overflowY:a}=getComputedStyle(r);if((a==="auto"||a==="scroll")&&r.scrollHeight>r.clientHeight+1)return r;r=r.parentElement;}return null}function Ct(o){return N(o)??document.documentElement}var ut=".layout-page-content .layout-line";function dt(o){let r=N(o);if(!r)return;let a=o.getBoundingClientRect(),m=r.getBoundingClientRect(),t=40;a.bottom>m.bottom-t?r.scrollTop+=a.bottom-m.bottom+t:a.top<m.top+t&&(r.scrollTop-=m.top-a.top+t);}function Mt({pagesContainerRef:o}){let r=useRef(null),a=useRef(-1),m=useCallback(b=>{if(!o.current)return null;let i=Ha(o.current);for(let d of i){let s=Number(d.dataset.pmStart),l=Number(d.dataset.pmEnd);if(d.classList.contains("layout-run-tab")){if(b>=s&&b<l)return d.getBoundingClientRect().left;continue}if(b>=s&&b<=l&&d.firstChild?.nodeType===Node.TEXT_NODE){let n=d.firstChild,e=Math.min(b-s,n.length),u=d.ownerDocument;if(!u)continue;let c=u.createRange();return c.setStart(n,e),c.setEnd(n,e),c.getBoundingClientRect().left}}let f=o.current.querySelectorAll(".layout-empty-run");for(let d of Array.from(f)){let s=d.closest(".layout-paragraph");if(!s)continue;let l=Number(s.dataset.pmStart),n=Number(s.dataset.pmEnd);if(b>=l&&b<=n)return d.getBoundingClientRect().left}return null},[o]),t=useCallback(b=>{if(!o.current)return null;let i=o.current.querySelectorAll(ut);for(let f of Array.from(i)){let d=f,s=d.querySelectorAll("span[data-pm-start][data-pm-end]");for(let l of Array.from(s)){let n=l,e=Number(n.dataset.pmStart),u=Number(n.dataset.pmEnd);if(b>=e&&b<=u)return d}}for(let f of Array.from(i)){let d=f,s=d.closest(".layout-paragraph");if(!s)continue;let l=Number(s.dataset.pmStart),n=Number(s.dataset.pmEnd);if(b>=l&&b<=n&&s.querySelector(".layout-line")===d)return d}return null},[o]),S=useCallback((b,i)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let n=b.closest(".layout-paragraph");return n?.dataset.pmStart?Number(n.dataset.pmStart)+1:null}for(let n of Array.from(f)){let e=n,u=e.getBoundingClientRect(),c=Number(e.dataset.pmStart),y=Number(e.dataset.pmEnd);if(e.classList.contains("layout-run-tab")){if(i>=u.left&&i<=u.right){let E=(u.left+u.right)/2;return i<E?c:y}continue}if(i>=u.left&&i<=u.right){let E=e.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return c;let p=E,L=e.ownerDocument;if(!L)return c;let w=0,M=p.length;for(;w<M;){let k=Math.floor((w+M)/2),H=L.createRange();H.setStart(p,k),H.setEnd(p,k),i<H.getBoundingClientRect().left?M=k:w=k+1;}if(w>0&&w<=p.length){let k=L.createRange();k.setStart(p,w-1),k.setEnd(p,w-1);let H=k.getBoundingClientRect().left;k.setStart(p,Math.min(w,p.length)),k.setEnd(p,Math.min(w,p.length));let h=k.getBoundingClientRect().left;if(Math.abs(i-H)<Math.abs(i-h))return c+(w-1)}return c+Math.min(w,y-c)}}let d=null,s=1/0;for(let n of Array.from(f)){let e=n,u=e.getBoundingClientRect(),c=i<u.left?u.left-i:i-u.right;c<s&&(s=c,d=e);}if(!d)return null;let l=d.getBoundingClientRect();return i<l.left?Number(d.dataset.pmStart):Number(d.dataset.pmEnd)},[]),x=useCallback((b,i)=>{if(i.key!=="ArrowUp"&&i.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(i.key)||i.key.length===1&&!i.ctrlKey&&!i.metaKey)&&(r.current=null,a.current=-1),false;if(i.ctrlKey||i.metaKey)return r.current=null,a.current=-1,false;if(!o.current)return false;let f=Array.from(o.current.querySelectorAll(ut));if(f.length===0)return false;let{from:d,anchor:s}=b.state.selection;if(r.current===null){let p=m(d);if(p===null)return false;r.current=p;}let l;if(a.current>=0&&a.current<f.length)l=a.current;else {let p=t(d);if(!p||(l=f.indexOf(p),l===-1))return false}let n=i.key==="ArrowUp"?l-1:l+1;if(n<0||n>=f.length)return a.current=-1,false;let e=f[n],u=S(e,r.current);if(u===null)return false;a.current=n;let{state:c,dispatch:y}=b,E=Math.max(0,Math.min(u,c.doc.content.size));try{let p=i.shiftKey?TextSelection.create(c.doc,s,E):TextSelection.create(c.doc,E);y(c.tr.setSelection(p));}catch{let p=c.doc.resolve(E),L=i.shiftKey?TextSelection.between(c.doc.resolve(s),p):TextSelection.near(p);y(c.tr.setSelection(L));}return dt(e),true},[o,m,t,S]);return {stickyXRef:r,lastVisualLineIndexRef:a,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}var R=40,B=12;function Ut({pagesContainerRef:o,onScrollExtendSelection:r}){let a=useRef(null),m=useRef({x:0,y:0}),t=useRef(false),S=useRef(null),x=useCallback(()=>{if(S.current)return S.current;let s=o.current;return s?(S.current=N(s),S.current):null},[o]),b=useCallback(()=>{t.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);},[]),i=useCallback(()=>{if(!t.current)return;let s=x();if(!s)return;let l=s.getBoundingClientRect(),{x:n,y:e}=m.current,u=0;if(e<l.top+R){let c=Math.max(0,l.top+R-e);u=-Math.min(B,c/R*B);}else if(e>l.bottom-R){let c=Math.max(0,e-(l.bottom-R));u=Math.min(B,c/R*B);}u!==0&&(s.scrollTop+=u,r(n,e)),a.current=requestAnimationFrame(i);},[x,r]),f=useCallback(()=>{t.current||(t.current=true,a.current=requestAnimationFrame(i));},[i]);return {updateMousePosition:useCallback((s,l)=>{if(m.current={x:s,y:l},!t.current){let n=x();if(!n)return;let e=n.getBoundingClientRect();(l<e.top+R||l>e.bottom-R)&&f();}},[x,f]),stopAutoScroll:b}}export{gt as a,at as b,Et as c,wt as d,rt as e,Ct as f,Mt as g,Ut as h};
|
|
1
|
+
import {e,h,i,n as n$1,f,m as m$1,k as k$1,l as l$1,j}from'./chunk-U7ZW2DOO.mjs';import {n,k,l,m}from'./chunk-MDTA25AN.mjs';import {Ha}from'./chunk-XQZTWWRF.mjs';import {d}from'./chunk-TAUMSKRE.mjs';import {useMemo,useState,useCallback,useRef,useEffect}from'react';import {TextSelection}from'prosemirror-state';function gt({document:o,onChange:r,onSelectionChange:a}){let m$2=useMemo(()=>new n,[]),[t,S]=useState({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),x=useCallback((l,n,e$1)=>{if(!o)return;let u=k(o,l);if(!u){m$2.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null});return}m$2.selectCell({tableIndex:l,rowIndex:n,columnIndex:e$1});let y=e(u,{tableIndex:l,rowIndex:n,columnIndex:e$1});S({context:y,table:u,tableIndex:l,rowIndex:n,columnIndex:e$1}),a?.(y);},[o,m$2,a]),b=useCallback(()=>{m$2.clearSelection(),S({context:null,table:null,tableIndex:null,rowIndex:null,columnIndex:null}),a?.(null);},[m$2,a]),i$1=useCallback(()=>!t.table||t.rowIndex===null||t.columnIndex===null?null:h(t.table,t.rowIndex,t.columnIndex),[t.columnIndex,t.rowIndex,t.table]),f$1=useCallback((l$1,n)=>{if(!o||!t.table||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let e=i(t.table,t.rowIndex,t.columnIndex,l$1,n);if(e===t.table)return;let u=l(o,t.tableIndex,e);r?.(u),u&&x(t.tableIndex,t.rowIndex,t.columnIndex);},[o,x,r,t.columnIndex,t.rowIndex,t.table,t.tableIndex]),d=useCallback(l$2=>{if(!o||!t.context||t.tableIndex===null||t.rowIndex===null||t.columnIndex===null)return;let n=t.table;if(!n)return;let e=null,u=null,c=t.rowIndex,y=t.columnIndex;switch(l$2){case "addRowAbove":e=j(n,t.rowIndex,"before"),c=t.rowIndex+1;break;case "addRowBelow":e=j(n,t.rowIndex,"after");break;case "addColumnLeft":e=l$1(n,t.columnIndex,"before"),y=t.columnIndex+1;break;case "addColumnRight":e=l$1(n,t.columnIndex,"after");break;case "deleteRow":n.rows.length>1&&(e=k$1(n,t.rowIndex),c>=e.rows.length&&(c=e.rows.length-1));break;case "deleteColumn":{if(f(n)>1){e=m$1(n,t.columnIndex);let p=f(e);y>=p&&(y=p-1);}break}case "mergeCells":t.context.selection.selectedCells&&(e=n$1(n,t.context.selection));break;case "splitCell":break;case "deleteTable":u=m(o,t.tableIndex),b(),r?.(u);return}e&&(u=l(o,t.tableIndex,e),r?.(u),u&&x(t.tableIndex,c,y));},[o,t,r,b,x]),s=useCallback((l,n,e)=>m$2.isCellSelected(l,n,e),[m$2,t]);return {state:t,handleCellClick:x,handleAction:d,getSplitCellConfig:i$1,applySplitCell:f$1,clearSelection:b,isCellSelected:s,tableContext:t.context}}function lt(o,r){return JSON.stringify(o)===JSON.stringify(r)}function at(o,r={}){let{maxEntries:a=100,groupingInterval:m=500,enableKeyboardShortcuts:t=true,isEqual:S=lt,onUndo:x,onRedo:b,containerRef:i}=r,[f,d]=useState(o),[s,l]=useState([]),[n,e]=useState([]),u=useRef(0),c=useRef(false),y=useCallback((h,g)=>{if(S(f,h))return;if(c.current){d(h);return}let T=Date.now();T-u.current<m&&s.length>0?l(V=>{let A=[...V];return A[A.length-1]={state:f,timestamp:T,description:g||A[A.length-1].description},A}):l(V=>{let A={state:f,timestamp:T,description:g},v=[...V,A];return v.length>a?v.slice(v.length-a):v}),e([]),d(h),u.current=T;},[f,S,m,a,s.length]),E=useCallback(()=>{if(s.length===0)return;c.current=true;let h=s[s.length-1];return l(g=>g.slice(0,-1)),e(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),x?.(h.state),h.state},[s,f,x]),p=useCallback(()=>{if(n.length===0)return;c.current=true;let h=n[n.length-1];return e(g=>g.slice(0,-1)),l(g=>[...g,{state:f,timestamp:Date.now()}]),d(h.state),setTimeout(()=>{c.current=false;},0),b?.(h.state),h.state},[n,f,b]),L=useCallback(()=>{l([]),e([]);},[]),w=useCallback(h=>{d(h??o),l([]),e([]),u.current=0;},[o]),M=useCallback(()=>[...s],[s]),k=useCallback(()=>[...n],[n]),H=useCallback(h=>{d(g=>h(g)),l(g=>g.map(T=>({...T,state:h(T.state)}))),e(g=>g.map(T=>({...T,state:h(T.state)})));},[]);return useEffect(()=>{if(!t)return;let h=T=>{if((T.ctrlKey||T.metaKey)&&T.key==="z"&&!T.shiftKey){T.preventDefault(),E();return}if((T.ctrlKey||T.metaKey)&&T.key==="y"||(T.ctrlKey||T.metaKey)&&T.key==="z"&&T.shiftKey){T.preventDefault(),p();return}},g=i?.current||document;return g.addEventListener("keydown",h),()=>{g.removeEventListener("keydown",h);}},[t,E,p,i]),{state:f,canUndo:s.length>0,canRedo:n.length>0,undoCount:s.length,redoCount:n.length,push:y,undo:E,redo:p,clear:L,reset:w,getUndoStack:M,getRedoStack:k,transformAll:H}}function Et(o,r={}){let a=at(o,r);return useEffect(()=>{a.push(o);},[o]),a}function wt(o,r={}){let a=useCallback((m,t)=>!(m?.package?.document!==t?.package?.document&&JSON.stringify(m?.package?.document)!==JSON.stringify(t?.package?.document)||m?.package?.headers!==t?.package?.headers||m?.package?.footers!==t?.package?.footers),[]);return at(o,{...r,isEqual:a})}var rt=class{constructor(r,a={}){d(this,"undoStack",[]);d(this,"redoStack",[]);d(this,"currentState");d(this,"maxEntries");d(this,"groupingInterval");d(this,"lastPushTime",0);d(this,"isEqual");this.currentState=r,this.maxEntries=a.maxEntries??100,this.groupingInterval=a.groupingInterval??500,this.isEqual=a.isEqual??lt;}get state(){return this.currentState}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}push(r,a){if(this.isEqual(this.currentState,r))return;let m=Date.now();m-this.lastPushTime<this.groupingInterval&&this.undoStack.length>0?this.undoStack[this.undoStack.length-1].timestamp=m:(this.undoStack.push({state:this.currentState,timestamp:m,description:a}),this.undoStack.length>this.maxEntries&&(this.undoStack=this.undoStack.slice(-this.maxEntries))),this.redoStack=[],this.currentState=r,this.lastPushTime=m;}undo(){if(this.undoStack.length===0)return;let r=this.undoStack.pop();return this.redoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=r.state,r.state}redo(){if(this.redoStack.length===0)return;let r=this.redoStack.pop();return this.undoStack.push({state:this.currentState,timestamp:Date.now()}),this.currentState=r.state,r.state}clear(){this.undoStack=[],this.redoStack=[];}reset(r){this.currentState=r??this.currentState,this.undoStack=[],this.redoStack=[],this.lastPushTime=0;}};function N(o){let r=o.parentElement;for(;r&&r!==document.documentElement;){let{overflowY:a}=getComputedStyle(r);if((a==="auto"||a==="scroll")&&r.scrollHeight>r.clientHeight+1)return r;r=r.parentElement;}return null}function Ct(o){return N(o)??document.documentElement}var ut=".layout-page-content .layout-line";function dt(o){let r=N(o);if(!r)return;let a=o.getBoundingClientRect(),m=r.getBoundingClientRect(),t=40;a.bottom>m.bottom-t?r.scrollTop+=a.bottom-m.bottom+t:a.top<m.top+t&&(r.scrollTop-=m.top-a.top+t);}function Mt({pagesContainerRef:o}){let r=useRef(null),a=useRef(-1),m=useCallback(b=>{if(!o.current)return null;let i=Ha(o.current);for(let d of i){let s=Number(d.dataset.pmStart),l=Number(d.dataset.pmEnd);if(d.classList.contains("layout-run-tab")){if(b>=s&&b<l)return d.getBoundingClientRect().left;continue}if(b>=s&&b<=l&&d.firstChild?.nodeType===Node.TEXT_NODE){let n=d.firstChild,e=Math.min(b-s,n.length),u=d.ownerDocument;if(!u)continue;let c=u.createRange();return c.setStart(n,e),c.setEnd(n,e),c.getBoundingClientRect().left}}let f=o.current.querySelectorAll(".layout-empty-run");for(let d of Array.from(f)){let s=d.closest(".layout-paragraph");if(!s)continue;let l=Number(s.dataset.pmStart),n=Number(s.dataset.pmEnd);if(b>=l&&b<=n)return d.getBoundingClientRect().left}return null},[o]),t=useCallback(b=>{if(!o.current)return null;let i=o.current.querySelectorAll(ut);for(let f of Array.from(i)){let d=f,s=d.querySelectorAll("span[data-pm-start][data-pm-end]");for(let l of Array.from(s)){let n=l,e=Number(n.dataset.pmStart),u=Number(n.dataset.pmEnd);if(b>=e&&b<=u)return d}}for(let f of Array.from(i)){let d=f,s=d.closest(".layout-paragraph");if(!s)continue;let l=Number(s.dataset.pmStart),n=Number(s.dataset.pmEnd);if(b>=l&&b<=n&&s.querySelector(".layout-line")===d)return d}return null},[o]),S=useCallback((b,i)=>{let f=b.querySelectorAll("span[data-pm-start][data-pm-end]");if(f.length===0){let n=b.closest(".layout-paragraph");return n?.dataset.pmStart?Number(n.dataset.pmStart)+1:null}for(let n of Array.from(f)){let e=n,u=e.getBoundingClientRect(),c=Number(e.dataset.pmStart),y=Number(e.dataset.pmEnd);if(e.classList.contains("layout-run-tab")){if(i>=u.left&&i<=u.right){let E=(u.left+u.right)/2;return i<E?c:y}continue}if(i>=u.left&&i<=u.right){let E=e.firstChild;if(!E||E.nodeType!==Node.TEXT_NODE)return c;let p=E,L=e.ownerDocument;if(!L)return c;let w=0,M=p.length;for(;w<M;){let k=Math.floor((w+M)/2),H=L.createRange();H.setStart(p,k),H.setEnd(p,k),i<H.getBoundingClientRect().left?M=k:w=k+1;}if(w>0&&w<=p.length){let k=L.createRange();k.setStart(p,w-1),k.setEnd(p,w-1);let H=k.getBoundingClientRect().left;k.setStart(p,Math.min(w,p.length)),k.setEnd(p,Math.min(w,p.length));let h=k.getBoundingClientRect().left;if(Math.abs(i-H)<Math.abs(i-h))return c+(w-1)}return c+Math.min(w,y-c)}}let d=null,s=1/0;for(let n of Array.from(f)){let e=n,u=e.getBoundingClientRect(),c=i<u.left?u.left-i:i-u.right;c<s&&(s=c,d=e);}if(!d)return null;let l=d.getBoundingClientRect();return i<l.left?Number(d.dataset.pmStart):Number(d.dataset.pmEnd)},[]),x=useCallback((b,i)=>{if(i.key!=="ArrowUp"&&i.key!=="ArrowDown")return (["ArrowLeft","ArrowRight","Home","End"].includes(i.key)||i.key.length===1&&!i.ctrlKey&&!i.metaKey)&&(r.current=null,a.current=-1),false;if(i.ctrlKey||i.metaKey)return r.current=null,a.current=-1,false;if(!o.current)return false;let f=Array.from(o.current.querySelectorAll(ut));if(f.length===0)return false;let{from:d,anchor:s}=b.state.selection;if(r.current===null){let p=m(d);if(p===null)return false;r.current=p;}let l;if(a.current>=0&&a.current<f.length)l=a.current;else {let p=t(d);if(!p||(l=f.indexOf(p),l===-1))return false}let n=i.key==="ArrowUp"?l-1:l+1;if(n<0||n>=f.length)return a.current=-1,false;let e=f[n],u=S(e,r.current);if(u===null)return false;a.current=n;let{state:c,dispatch:y}=b,E=Math.max(0,Math.min(u,c.doc.content.size));try{let p=i.shiftKey?TextSelection.create(c.doc,s,E):TextSelection.create(c.doc,E);y(c.tr.setSelection(p));}catch{let p=c.doc.resolve(E),L=i.shiftKey?TextSelection.between(c.doc.resolve(s),p):TextSelection.near(p);y(c.tr.setSelection(L));}return dt(e),true},[o,m,t,S]);return {stickyXRef:r,lastVisualLineIndexRef:a,getCaretClientX:m,findLineElementAtPosition:t,findPositionOnLineAtClientX:S,handlePMKeyDown:x}}var R=40,B=12;function Ut({pagesContainerRef:o,onScrollExtendSelection:r}){let a=useRef(null),m=useRef({x:0,y:0}),t=useRef(false),S=useRef(null),x=useCallback(()=>{if(S.current)return S.current;let s=o.current;return s?(S.current=N(s),S.current):null},[o]),b=useCallback(()=>{t.current=false,a.current!==null&&(cancelAnimationFrame(a.current),a.current=null);},[]),i=useCallback(()=>{if(!t.current)return;let s=x();if(!s)return;let l=s.getBoundingClientRect(),{x:n,y:e}=m.current,u=0;if(e<l.top+R){let c=Math.max(0,l.top+R-e);u=-Math.min(B,c/R*B);}else if(e>l.bottom-R){let c=Math.max(0,e-(l.bottom-R));u=Math.min(B,c/R*B);}u!==0&&(s.scrollTop+=u,r(n,e)),a.current=requestAnimationFrame(i);},[x,r]),f=useCallback(()=>{t.current||(t.current=true,a.current=requestAnimationFrame(i));},[i]);return {updateMousePosition:useCallback((s,l)=>{if(m.current={x:s,y:l},!t.current){let n=x();if(!n)return;let e=n.getBoundingClientRect();(l<e.top+R||l>e.bottom-R)&&f();}},[x,f]),stopAutoScroll:b}}export{gt as a,at as b,Et as c,wt as d,rt as e,Ct as f,Mt as g,Ut as h};
|