@embedpdf/plugin-redaction 1.3.11 → 1.3.13
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +87 -30
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +10 -3
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/redaction-plugin.d.ts +5 -1
- package/dist/lib/types.d.ts +25 -5
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +24 -10
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +24 -10
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-redaction.d.ts +5 -1
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-redaction.d.ts +5 -1
- package/dist/vue/hooks/use-redaction.d.ts +102 -0
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.js +32 -16
- package/dist/vue/index.js.map +1 -1
- package/package.json +14 -9
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),i="START_REDACTION",n="END_REDACTION",a="ADD_PENDING",s="REMOVE_PENDING",r="CLEAR_PENDING",o="SELECT_PENDING",c="DESELECT_PENDING",l=e=>({type:a,payload:e}),d=(e,t)=>({type:s,payload:{page:e,id:t}}),g=()=>({type:r});const u=class extends e.BasePlugin{constructor(a,s,r){var o,c,d,g,u;super(a,s),this.redactionSelection$=e.createBehaviorEmitter(),this.pending$=e.createBehaviorEmitter(),this.selected$=e.createBehaviorEmitter(),this.config=r,this.selectionCapability=null==(o=this.registry.getPlugin("selection"))?void 0:o.provides(),this.interactionManagerCapability=null==(c=this.registry.getPlugin("interaction-manager"))?void 0:c.provides(),this.interactionManagerCapability&&this.interactionManagerCapability.registerMode({id:"marqueeRedact",scope:"page",exclusive:!0,cursor:"crosshair"}),this.interactionManagerCapability&&this.selectionCapability&&(this.interactionManagerCapability.registerMode({id:"redactSelection",scope:"page",exclusive:!1}),this.selectionCapability.enableForMode("redactSelection")),this.unsubscribeModeChange=null==(d=this.interactionManagerCapability)?void 0:d.onModeChange((e=>{"redactSelection"===e.activeMode||"marqueeRedact"===e.activeMode?this.dispatch({type:i}):this.dispatch({type:n})})),this.unsubscribeSelectionChange=null==(g=this.selectionCapability)?void 0:g.onSelectionChange((()=>{if(!this.selectionCapability)return;if(!this.state.isRedacting)return;const e=this.selectionCapability.getFormattedSelection();this.redactionSelection$.emit(e)})),this.unsubscribeEndSelection=null==(u=this.selectionCapability)?void 0:u.onEndSelection((()=>{if(!this.selectionCapability)return;if(!this.state.isRedacting)return;const e=this.selectionCapability.getFormattedSelection().map((e=>({id:t.uuidV4(),kind:"text",page:e.pageIndex,boundingRect:e.rect,rects:e.segmentRects})));this.dispatch(l(e)),this.redactionSelection$.emit([]),this.selectionCapability.clear(),this.pending$.emit(this.state.pending),e.length&&this.selectPending(e[e.length-1].page,e[e.length-1].id)}))}async initialize(e){}buildCapability(){return{onRedactionSelectionChange:this.redactionSelection$.on,queueCurrentSelectionAsPending:()=>this.queueCurrentSelectionAsPending(),enableMarqueeRedact:()=>this.enableMarqueeRedact(),toggleMarqueeRedact:()=>this.toggleMarqueeRedact(),isMarqueeRedactActive:()=>{var e;return"marqueeRedact"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())},enableRedactSelection:()=>this.enableRedactSelection(),toggleRedactSelection:()=>this.toggleRedactSelection(),isRedactSelectionActive:()=>{var e;return"redactSelection"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())},onPendingChange:this.pending$.on,removePending:(e,t)=>{this.dispatch(d(e,t)),this.pending$.emit(this.state.pending)},clearPending:()=>{this.dispatch(g()),this.pending$.emit(this.state.pending)},commitAllPending:()=>this.commitAllPending(),commitPending:(e,t)=>this.commitPendingOne(e,t),endRedaction:()=>this.endRedaction(),startRedaction:()=>this.startRedaction(),onSelectionChange:this.selected$.on,selectPending:(e,t)=>this.selectPending(e,t),deselectPending:()=>this.deselectPending(),registerMarqueeOnPage:e=>this.registerMarqueeOnPage(e)}}selectPending(e,t){var i;this.dispatch(((e,t)=>({type:o,payload:{page:e,id:t}}))(e,t)),null==(i=this.selectionCapability)||i.clear(),this.selected$.emit(this.state.selected)}deselectPending(){this.dispatch({type:c}),this.selected$.emit(this.state.selected)}enableRedactSelection(){var e;null==(e=this.interactionManagerCapability)||e.activate("redactSelection")}toggleRedactSelection(){var e,t,i;"redactSelection"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())?null==(t=this.interactionManagerCapability)||t.activateDefaultMode():null==(i=this.interactionManagerCapability)||i.activate("redactSelection")}enableMarqueeRedact(){var e;null==(e=this.interactionManagerCapability)||e.activate("marqueeRedact")}toggleMarqueeRedact(){var e,t,i;"marqueeRedact"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())?null==(t=this.interactionManagerCapability)||t.activateDefaultMode():null==(i=this.interactionManagerCapability)||i.activate("marqueeRedact")}startRedaction(){var e;null==(e=this.interactionManagerCapability)||e.activate("redactSelection")}endRedaction(){var e;null==(e=this.interactionManagerCapability)||e.activateDefaultMode()}registerMarqueeOnPage(i){if(!this.interactionManagerCapability)return this.logger.warn("RedactionPlugin","MissingDependency","Interaction manager plugin not loaded, marquee redaction disabled"),()=>{};const n=this.coreState.core.document;if(!n)return this.logger.warn("RedactionPlugin","DocumentNotFound","Document not found"),()=>{};const a=n.pages[i.pageIndex];if(!a)return this.logger.warn("RedactionPlugin","PageNotFound",`Page ${i.pageIndex} not found`),()=>{};const s=function(t){const{pageSize:i,scale:n,minDragPx:a=5,onPreview:s,onCommit:r}=t;let o=null,c=null;return{onPointerDown:(e,t)=>{var i;o=e,c={origin:{x:e.x,y:e.y},size:{width:0,height:0}},null==s||s(c),null==(i=t.setPointerCapture)||i.call(t)},onPointerMove:t=>{if(!o)return;const n=e.clamp(t.x,0,i.width),a=e.clamp(t.y,0,i.height);c={origin:{x:Math.min(o.x,n),y:Math.min(o.y,a)},size:{width:Math.abs(n-o.x),height:Math.abs(a-o.y)}},null==s||s(c)},onPointerUp:(e,t)=>{var i;c&&Math.max(c.size.width,c.size.height)*n>a&&(null==r||r(c)),o=null,c=null,null==s||s(null),null==(i=t.releasePointerCapture)||i.call(t)},onPointerCancel:(e,t)=>{var i;o=null,c=null,null==s||s(null),null==(i=t.releasePointerCapture)||i.call(t)}}}({pageSize:a.size,scale:i.scale,onPreview:i.callback.onPreview,onCommit:e=>{var n,a;const s={id:t.uuidV4(),kind:"area",page:i.pageIndex,rect:e};this.dispatch(l([s])),this.pending$.emit(this.state.pending),null==(a=(n=i.callback).onCommit)||a.call(n,e),this.enableRedactSelection(),this.selectPending(i.pageIndex,s.id)}}),r=this.interactionManagerCapability.registerAlways({handlers:{onPointerDown:(e,t)=>{t.target===t.currentTarget&&this.deselectPending()}},scope:{type:"page",pageIndex:i.pageIndex}}),o=this.interactionManagerCapability.registerHandlers({modeId:"marqueeRedact",handlers:s,pageIndex:i.pageIndex});return()=>{r(),o()}}queueCurrentSelectionAsPending(){var e;if(!this.selectionCapability)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"[RedactionPlugin] selection plugin required"});if(!this.coreState.core.document)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const i=this.selectionCapability.getFormattedSelection();if(!i.length)return t.PdfTaskHelper.resolve(!0);const n=t.uuidV4(),a=i.map((e=>({id:n,kind:"text",page:e.pageIndex,boundingRect:e.rect,rects:e.segmentRects})));this.enableRedactSelection(),this.dispatch(l(a)),this.pending$.emit(this.state.pending);const s=a[a.length-1];return this.selectPending(s.page,s.id),this.redactionSelection$.emit([]),null==(e=this.selectionCapability)||e.clear(),t.PdfTaskHelper.resolve(!0)}commitPendingOne(i,n){const a=this.coreState.core.document;if(!a)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const s=(this.state.pending[i]??[]).find((e=>e.id===n));if(!s)return t.PdfTaskHelper.resolve(!0);const r="text"===s.kind?s.rects:[s.rect],o=a.pages[i];if(!o)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Page not found"});const c=new t.Task;return this.engine.redactTextInRects(a,o,r,{drawBlackBoxes:this.config.drawBlackBoxes}).wait((()=>{this.dispatch(d(i,n)),this.pending$.emit(this.state.pending),this.dispatchCoreAction(e.refreshPages([i])),c.resolve(!0)}),(()=>c.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"}))),c}commitAllPending(){const i=this.coreState.core.document;if(!i)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const n=new Map;for(const[e,t]of Object.entries(this.state.pending)){const i=Number(e),a=n.get(i)??[];for(const e of t)"text"===e.kind?a.push(...e.rects):a.push(e.rect);n.set(i,a)}const a=Array.from(n.entries()).filter((([e,t])=>t.length>0)).map((([e])=>e)),s=[];for(const[e,t]of n){const n=i.pages[e];n&&(t.length&&s.push(this.engine.redactTextInRects(i,n,t,{drawBlackBoxes:this.config.drawBlackBoxes})))}const r=new t.Task;return t.Task.all(s).wait((()=>{this.dispatch(g()),this.dispatchCoreAction(e.refreshPages(a)),this.pending$.emit(this.state.pending),r.resolve(!0)}),(()=>r.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"}))),r}onStoreUpdated(e,t){this.pending$.emit(t.pending),this.selected$.emit(t.selected)}async destroy(){var e,t,i;this.redactionSelection$.clear(),this.pending$.clear(),null==(e=this.unsubscribeSelectionChange)||e.call(this),null==(t=this.unsubscribeEndSelection)||t.call(this),null==(i=this.unsubscribeModeChange)||i.call(this),await super.destroy()}};u.id="redaction";let h=u;const p="redaction",m={id:p,name:"Redaction Plugin",version:"1.0.0",provides:["redaction"],requires:[],optional:["interaction-manager","selection"],defaultConfig:{enabled:!0,drawBlackBoxes:!0}},P={isRedacting:!1,pending:{},selected:null},b={manifest:m,create:(e,t)=>new h(p,e,t),reducer:(e=P,t)=>{switch(t.type){case a:{const i={...e.pending};for(const e of t.payload)i[e.page]=(i[e.page]??[]).concat(e);return{...e,pending:i}}case s:{const{page:i,id:n}=t.payload,a=(e.pending[i]??[]).filter((e=>e.id!==n)),s={...e.pending,[i]:a},r=e.selected&&!(e.selected.page===i&&e.selected.id===n);return{...e,pending:s,selected:r?e.selected:null}}case r:return{...e,pending:{},selected:null};case o:return{...e,selected:{page:t.payload.page,id:t.payload.id}};case c:return{...e,selected:null};case i:return{...e,isRedacting:!0};case n:return{...e,pending:{},selected:null,isRedacting:!1};default:return e}},initialState:P};exports.REDACTION_PLUGIN_ID=p,exports.RedactionPlugin=h,exports.RedactionPluginPackage=b,exports.getPendingRedactionsCount=e=>Object.values(e.pending).reduce(((e,t)=>e+((null==t?void 0:t.length)??0)),0),exports.hasPendingRedactions=e=>Object.values(e.pending).some((e=>((null==e?void 0:e.length)??0)>0)),exports.manifest=m;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models");var i=(e=>(e.MarqueeRedact="marqueeRedact",e.RedactSelection="redactSelection",e))(i||{});const n="START_REDACTION",a="END_REDACTION",s="ADD_PENDING",c="REMOVE_PENDING",o="CLEAR_PENDING",r="SELECT_PENDING",l="DESELECT_PENDING",d=e=>({type:s,payload:e}),g=(e,t)=>({type:c,payload:{page:e,id:t}}),h=()=>({type:o}),u=e=>({type:n,payload:e});const p=class extends e.BasePlugin{constructor(n,s,c){var o,r,l,g,h;super(n,s),this.redactionSelection$=e.createBehaviorEmitter(),this.pending$=e.createBehaviorEmitter(),this.selected$=e.createBehaviorEmitter(),this.state$=e.createBehaviorEmitter(),this.events$=e.createBehaviorEmitter(),this.config=c,this.selectionCapability=null==(o=this.registry.getPlugin("selection"))?void 0:o.provides(),this.interactionManagerCapability=null==(r=this.registry.getPlugin("interaction-manager"))?void 0:r.provides(),this.interactionManagerCapability&&this.interactionManagerCapability.registerMode({id:i.MarqueeRedact,scope:"page",exclusive:!0,cursor:"crosshair"}),this.interactionManagerCapability&&this.selectionCapability&&(this.interactionManagerCapability.registerMode({id:i.RedactSelection,scope:"page",exclusive:!1}),this.selectionCapability.enableForMode(i.RedactSelection)),this.unsubscribeModeChange=null==(l=this.interactionManagerCapability)?void 0:l.onModeChange((e=>{e.activeMode===i.RedactSelection?this.dispatch(u(i.RedactSelection)):e.activeMode===i.MarqueeRedact?this.dispatch(u(i.MarqueeRedact)):this.dispatch({type:a})})),this.unsubscribeSelectionChange=null==(g=this.selectionCapability)?void 0:g.onSelectionChange((()=>{if(!this.selectionCapability)return;if(!this.state.isRedacting)return;const e=this.selectionCapability.getFormattedSelection();this.redactionSelection$.emit(e)})),this.unsubscribeEndSelection=null==(h=this.selectionCapability)?void 0:h.onEndSelection((()=>{if(!this.selectionCapability)return;if(!this.state.isRedacting)return;const e=this.selectionCapability.getFormattedSelection().map((e=>({id:t.uuidV4(),kind:"text",page:e.pageIndex,rect:e.rect,rects:e.segmentRects})));this.dispatch(d(e)),this.redactionSelection$.emit([]),this.selectionCapability.clear(),this.pending$.emit(this.state.pending),e.length&&this.selectPending(e[e.length-1].page,e[e.length-1].id)}))}async initialize(e){}buildCapability(){return{queueCurrentSelectionAsPending:()=>this.queueCurrentSelectionAsPending(),enableMarqueeRedact:()=>this.enableMarqueeRedact(),toggleMarqueeRedact:()=>this.toggleMarqueeRedact(),isMarqueeRedactActive:()=>{var e;return(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())===i.MarqueeRedact},enableRedactSelection:()=>this.enableRedactSelection(),toggleRedactSelection:()=>this.toggleRedactSelection(),isRedactSelectionActive:()=>{var e;return(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())===i.RedactSelection},addPending:e=>{this.dispatch(d(e)),this.pending$.emit(this.state.pending),this.events$.emit({type:"add",items:e})},removePending:(e,t)=>{this.dispatch(g(e,t)),this.pending$.emit(this.state.pending),this.events$.emit({type:"remove",page:e,id:t})},clearPending:()=>{this.dispatch(h()),this.pending$.emit(this.state.pending),this.events$.emit({type:"clear"})},commitAllPending:()=>this.commitAllPending(),commitPending:(e,t)=>this.commitPendingOne(e,t),endRedaction:()=>this.endRedaction(),startRedaction:()=>this.startRedaction(),selectPending:(e,t)=>this.selectPending(e,t),deselectPending:()=>this.deselectPending(),onSelectedChange:this.selected$.on,onRedactionEvent:this.events$.on,onStateChange:this.state$.on,onPendingChange:this.pending$.on}}onRedactionSelectionChange(e){return this.redactionSelection$.on(e)}selectPending(e,t){var i;this.dispatch(((e,t)=>({type:r,payload:{page:e,id:t}}))(e,t)),null==(i=this.selectionCapability)||i.clear(),this.selected$.emit(this.state.selected)}deselectPending(){this.dispatch({type:l}),this.selected$.emit(this.state.selected)}enableRedactSelection(){var e;null==(e=this.interactionManagerCapability)||e.activate(i.RedactSelection)}toggleRedactSelection(){var e,t,n;(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())===i.RedactSelection?null==(t=this.interactionManagerCapability)||t.activateDefaultMode():null==(n=this.interactionManagerCapability)||n.activate(i.RedactSelection)}enableMarqueeRedact(){var e;null==(e=this.interactionManagerCapability)||e.activate(i.MarqueeRedact)}toggleMarqueeRedact(){var e,t,n;(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())===i.MarqueeRedact?null==(t=this.interactionManagerCapability)||t.activateDefaultMode():null==(n=this.interactionManagerCapability)||n.activate(i.MarqueeRedact)}startRedaction(){var e;null==(e=this.interactionManagerCapability)||e.activate(i.RedactSelection)}endRedaction(){var e;null==(e=this.interactionManagerCapability)||e.activateDefaultMode()}registerMarqueeOnPage(n){if(!this.interactionManagerCapability)return this.logger.warn("RedactionPlugin","MissingDependency","Interaction manager plugin not loaded, marquee redaction disabled"),()=>{};const a=this.coreState.core.document;if(!a)return this.logger.warn("RedactionPlugin","DocumentNotFound","Document not found"),()=>{};const s=a.pages[n.pageIndex];if(!s)return this.logger.warn("RedactionPlugin","PageNotFound",`Page ${n.pageIndex} not found`),()=>{};const c=function(t){const{pageSize:i,scale:n,minDragPx:a=5,onPreview:s,onCommit:c}=t;let o=null,r=null;return{onPointerDown:(e,t)=>{var i;o=e,r={origin:{x:e.x,y:e.y},size:{width:0,height:0}},null==s||s(r),null==(i=t.setPointerCapture)||i.call(t)},onPointerMove:t=>{if(!o)return;const n=e.clamp(t.x,0,i.width),a=e.clamp(t.y,0,i.height);r={origin:{x:Math.min(o.x,n),y:Math.min(o.y,a)},size:{width:Math.abs(n-o.x),height:Math.abs(a-o.y)}},null==s||s(r)},onPointerUp:(e,t)=>{var i;r&&Math.max(r.size.width,r.size.height)*n>a&&(null==c||c(r)),o=null,r=null,null==s||s(null),null==(i=t.releasePointerCapture)||i.call(t)},onPointerCancel:(e,t)=>{var i;o=null,r=null,null==s||s(null),null==(i=t.releasePointerCapture)||i.call(t)}}}({pageSize:s.size,scale:n.scale,onPreview:n.callback.onPreview,onCommit:e=>{var i,a;const s={id:t.uuidV4(),kind:"area",page:n.pageIndex,rect:e};this.dispatch(d([s])),this.pending$.emit(this.state.pending),null==(a=(i=n.callback).onCommit)||a.call(i,e),this.enableRedactSelection(),this.selectPending(n.pageIndex,s.id)}}),o=this.interactionManagerCapability.registerAlways({handlers:{onPointerDown:(e,t)=>{t.target===t.currentTarget&&this.deselectPending()}},scope:{type:"page",pageIndex:n.pageIndex}}),r=this.interactionManagerCapability.registerHandlers({modeId:i.MarqueeRedact,handlers:c,pageIndex:n.pageIndex});return()=>{o(),r()}}queueCurrentSelectionAsPending(){var e;if(!this.selectionCapability)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"[RedactionPlugin] selection plugin required"});if(!this.coreState.core.document)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const i=this.selectionCapability.getFormattedSelection();if(!i.length)return t.PdfTaskHelper.resolve(!0);const n=t.uuidV4(),a=i.map((e=>({id:n,kind:"text",page:e.pageIndex,rect:e.rect,rects:e.segmentRects})));this.enableRedactSelection(),this.dispatch(d(a)),this.pending$.emit(this.state.pending);const s=a[a.length-1];return this.selectPending(s.page,s.id),this.redactionSelection$.emit([]),null==(e=this.selectionCapability)||e.clear(),t.PdfTaskHelper.resolve(!0)}commitPendingOne(i,n){const a=this.coreState.core.document;if(!a)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const s=(this.state.pending[i]??[]).find((e=>e.id===n));if(!s)return t.PdfTaskHelper.resolve(!0);const c="text"===s.kind?s.rects:[s.rect],o=a.pages[i];if(!o)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Page not found"});const r=new t.Task;return this.engine.redactTextInRects(a,o,c,{drawBlackBoxes:this.config.drawBlackBoxes}).wait((()=>{this.dispatch(g(i,n)),this.pending$.emit(this.state.pending),this.dispatchCoreAction(e.refreshPages([i])),this.events$.emit({type:"commit",success:!0}),r.resolve(!0)}),(e=>{this.events$.emit({type:"commit",success:!1,error:e.reason}),r.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"})})),r}commitAllPending(){const i=this.coreState.core.document;if(!i)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Document not found"});const n=new Map;for(const[e,t]of Object.entries(this.state.pending)){const i=Number(e),a=n.get(i)??[];for(const e of t)"text"===e.kind?a.push(...e.rects):a.push(e.rect);n.set(i,a)}const a=Array.from(n.entries()).filter((([e,t])=>t.length>0)).map((([e])=>e)),s=[];for(const[e,t]of n){const n=i.pages[e];n&&(t.length&&s.push(this.engine.redactTextInRects(i,n,t,{drawBlackBoxes:this.config.drawBlackBoxes})))}const c=new t.Task;return t.Task.all(s).wait((()=>{this.dispatch(h()),this.dispatchCoreAction(e.refreshPages(a)),this.pending$.emit(this.state.pending),this.events$.emit({type:"commit",success:!0}),c.resolve(!0)}),(e=>{this.events$.emit({type:"commit",success:!1,error:e.reason}),c.reject({code:t.PdfErrorCode.Unknown,message:"Failed to commit redactions"})})),c}onStoreUpdated(e,t){this.pending$.emit(t.pending),this.selected$.emit(t.selected),this.state$.emit(t)}async destroy(){var e,t,i;this.redactionSelection$.clear(),this.pending$.clear(),this.state$.clear(),this.events$.clear(),null==(e=this.unsubscribeSelectionChange)||e.call(this),null==(t=this.unsubscribeEndSelection)||t.call(this),null==(i=this.unsubscribeModeChange)||i.call(this),await super.destroy()}};p.id="redaction";let m=p;const v="redaction",y={id:v,name:"Redaction Plugin",version:"1.0.0",provides:["redaction"],requires:[],optional:["interaction-manager","selection"],defaultConfig:{enabled:!0,drawBlackBoxes:!0}},C=e=>Object.values(e).reduce(((e,t)=>e+t.length),0),P={isRedacting:!1,activeType:null,pending:{},pendingCount:0,selected:null},b={manifest:y,create:(e,t)=>new m(v,e,t),reducer:(e=P,t)=>{switch(t.type){case s:{const i={...e.pending};for(const e of t.payload)i[e.page]=(i[e.page]??[]).concat(e);return{...e,pending:i,pendingCount:C(i)}}case c:{const{page:i,id:n}=t.payload,a=(e.pending[i]??[]).filter((e=>e.id!==n)),s={...e.pending,[i]:a},c=e.selected&&!(e.selected.page===i&&e.selected.id===n);return{...e,pending:s,pendingCount:C(s),selected:c?e.selected:null}}case o:return{...e,pending:{},pendingCount:0,selected:null};case r:return{...e,selected:{page:t.payload.page,id:t.payload.id}};case l:return{...e,selected:null};case n:return{...e,isRedacting:!0,activeType:t.payload};case a:return{...e,pending:{},pendingCount:0,selected:null,isRedacting:!1,activeType:null};case"SET_ACTIVE_TYPE":return{...e,activeType:t.payload};default:return e}},initialState:P};exports.REDACTION_PLUGIN_ID=v,exports.RedactionMode=i,exports.RedactionPlugin=m,exports.RedactionPluginPackage=b,exports.getPendingRedactionsCount=e=>Object.values(e.pending).reduce(((e,t)=>e+((null==t?void 0:t.length)??0)),0),exports.hasPendingRedactions=e=>Object.values(e.pending).some((e=>((null==e?void 0:e.length)??0)>0)),exports.initialState=P,exports.manifest=y;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/lib/actions.ts","../src/lib/redaction-plugin.ts","../src/lib/handlers/marquee-redact.handler.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts","../src/lib/selectors.ts"],"sourcesContent":["import { Action } from '@embedpdf/core';\nimport { RedactionItem } from './types';\n\nexport const START_REDACTION = 'START_REDACTION';\nexport const END_REDACTION = 'END_REDACTION';\n\nexport const ADD_PENDING = 'ADD_PENDING';\nexport const REMOVE_PENDING = 'REMOVE_PENDING';\nexport const CLEAR_PENDING = 'CLEAR_PENDING';\n\nexport const SELECT_PENDING = 'SELECT_PENDING';\nexport const DESELECT_PENDING = 'DESELECT_PENDING';\n\nexport interface StartRedactionAction extends Action {\n type: typeof START_REDACTION;\n}\nexport interface EndRedactionAction extends Action {\n type: typeof END_REDACTION;\n}\n\nexport interface AddPendingAction extends Action {\n type: typeof ADD_PENDING;\n payload: RedactionItem[];\n}\nexport interface RemovePendingAction extends Action {\n type: typeof REMOVE_PENDING;\n payload: { page: number; id: string };\n}\nexport interface ClearPendingAction extends Action {\n type: typeof CLEAR_PENDING;\n}\n\nexport interface SelectPendingAction extends Action {\n type: typeof SELECT_PENDING;\n payload: { page: number; id: string };\n}\nexport interface DeselectPendingAction extends Action {\n type: typeof DESELECT_PENDING;\n}\n\nexport type RedactionAction =\n | StartRedactionAction\n | EndRedactionAction\n | AddPendingAction\n | RemovePendingAction\n | ClearPendingAction\n | SelectPendingAction\n | DeselectPendingAction;\n\nexport const addPending = (items: RedactionItem[]): AddPendingAction => ({\n type: ADD_PENDING,\n payload: items,\n});\nexport const removePending = (page: number, id: string): RemovePendingAction => ({\n type: REMOVE_PENDING,\n payload: { page, id },\n});\nexport const clearPending = (): ClearPendingAction => ({ type: CLEAR_PENDING });\n\nexport const startRedaction = (): StartRedactionAction => ({ type: START_REDACTION });\nexport const endRedaction = (): EndRedactionAction => ({ type: END_REDACTION });\n\nexport const selectPending = (page: number, id: string): SelectPendingAction => ({\n type: SELECT_PENDING,\n payload: { page, id },\n});\nexport const deselectPending = (): DeselectPendingAction => ({ type: DESELECT_PENDING });\n","import {\n RedactionPluginConfig,\n RedactionCapability,\n RedactionState,\n RegisterMarqueeOnPageOptions,\n RedactionItem,\n SelectedRedaction,\n} from './types';\nimport {\n BasePlugin,\n createBehaviorEmitter,\n PluginRegistry,\n refreshDocument,\n refreshPages,\n Unsubscribe,\n} from '@embedpdf/core';\nimport {\n ignore,\n PdfEngine,\n PdfErrorCode,\n PdfErrorReason,\n PdfTask,\n PdfTaskHelper,\n Rect,\n Task,\n uuidV4,\n} from '@embedpdf/models';\nimport {\n FormattedSelection,\n SelectionCapability,\n SelectionPlugin,\n} from '@embedpdf/plugin-selection';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport {\n addPending,\n clearPending,\n deselectPending,\n endRedaction,\n removePending,\n selectPending,\n startRedaction,\n} from './actions';\nimport { createMarqueeHandler } from './handlers';\n\nexport class RedactionPlugin extends BasePlugin<\n RedactionPluginConfig,\n RedactionCapability,\n RedactionState\n> {\n static readonly id = 'redaction' as const;\n private config: RedactionPluginConfig;\n\n private selectionCapability: SelectionCapability | undefined;\n private interactionManagerCapability: InteractionManagerCapability | undefined;\n\n private readonly redactionSelection$ = createBehaviorEmitter<FormattedSelection[]>();\n private readonly pending$ = createBehaviorEmitter<Record<number, RedactionItem[]>>();\n private readonly selected$ = createBehaviorEmitter<SelectedRedaction | null>();\n\n private readonly unsubscribeSelectionChange: Unsubscribe | undefined;\n private readonly unsubscribeEndSelection: Unsubscribe | undefined;\n private readonly unsubscribeModeChange: Unsubscribe | undefined;\n\n constructor(id: string, registry: PluginRegistry, config: RedactionPluginConfig) {\n super(id, registry);\n this.config = config;\n\n this.selectionCapability = this.registry.getPlugin<SelectionPlugin>('selection')?.provides();\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')\n ?.provides();\n\n if (this.interactionManagerCapability) {\n this.interactionManagerCapability.registerMode({\n id: 'marqueeRedact',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\n }\n\n if (this.interactionManagerCapability && this.selectionCapability) {\n this.interactionManagerCapability.registerMode({\n id: 'redactSelection',\n scope: 'page',\n exclusive: false,\n });\n this.selectionCapability.enableForMode('redactSelection');\n }\n\n this.unsubscribeModeChange = this.interactionManagerCapability?.onModeChange((state) => {\n if (state.activeMode === 'redactSelection' || state.activeMode === 'marqueeRedact')\n this.dispatch(startRedaction());\n else this.dispatch(endRedaction());\n });\n\n this.unsubscribeSelectionChange = this.selectionCapability?.onSelectionChange(() => {\n if (!this.selectionCapability) return;\n if (!this.state.isRedacting) return;\n const formattedSelection = this.selectionCapability.getFormattedSelection();\n this.redactionSelection$.emit(formattedSelection);\n });\n\n this.unsubscribeEndSelection = this.selectionCapability?.onEndSelection(() => {\n if (!this.selectionCapability) return;\n if (!this.state.isRedacting) return;\n\n const formattedSelection = this.selectionCapability.getFormattedSelection();\n\n const items: RedactionItem[] = formattedSelection.map((s) => ({\n id: uuidV4(),\n kind: 'text',\n page: s.pageIndex,\n boundingRect: s.rect,\n rects: s.segmentRects,\n }));\n\n this.dispatch(addPending(items));\n this.redactionSelection$.emit([]);\n this.selectionCapability.clear();\n this.pending$.emit(this.state.pending);\n if (items.length) {\n this.selectPending(items[items.length - 1].page, items[items.length - 1].id);\n }\n });\n }\n\n async initialize(_config: RedactionPluginConfig): Promise<void> {}\n\n protected buildCapability(): RedactionCapability {\n return {\n onRedactionSelectionChange: this.redactionSelection$.on,\n\n queueCurrentSelectionAsPending: () => this.queueCurrentSelectionAsPending(),\n\n enableMarqueeRedact: () => this.enableMarqueeRedact(),\n toggleMarqueeRedact: () => this.toggleMarqueeRedact(),\n isMarqueeRedactActive: () =>\n this.interactionManagerCapability?.getActiveMode() === 'marqueeRedact',\n\n enableRedactSelection: () => this.enableRedactSelection(),\n toggleRedactSelection: () => this.toggleRedactSelection(),\n isRedactSelectionActive: () =>\n this.interactionManagerCapability?.getActiveMode() === 'redactSelection',\n\n onPendingChange: this.pending$.on,\n removePending: (page, id) => {\n this.dispatch(removePending(page, id));\n this.pending$.emit(this.state.pending);\n },\n clearPending: () => {\n this.dispatch(clearPending());\n this.pending$.emit(this.state.pending);\n },\n commitAllPending: () => this.commitAllPending(),\n commitPending: (page, id) => this.commitPendingOne(page, id),\n\n endRedaction: () => this.endRedaction(),\n startRedaction: () => this.startRedaction(),\n\n onSelectionChange: this.selected$.on,\n selectPending: (page, id) => this.selectPending(page, id),\n deselectPending: () => this.deselectPending(),\n\n registerMarqueeOnPage: (opts) => this.registerMarqueeOnPage(opts),\n };\n }\n\n private selectPending(page: number, id: string) {\n this.dispatch(selectPending(page, id));\n this.selectionCapability?.clear();\n this.selected$.emit(this.state.selected);\n }\n private deselectPending() {\n this.dispatch(deselectPending());\n this.selected$.emit(this.state.selected);\n }\n\n private enableRedactSelection() {\n this.interactionManagerCapability?.activate('redactSelection');\n }\n private toggleRedactSelection() {\n if (this.interactionManagerCapability?.getActiveMode() === 'redactSelection')\n this.interactionManagerCapability?.activateDefaultMode();\n else this.interactionManagerCapability?.activate('redactSelection');\n }\n\n private enableMarqueeRedact() {\n this.interactionManagerCapability?.activate('marqueeRedact');\n }\n private toggleMarqueeRedact() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeRedact')\n this.interactionManagerCapability?.activateDefaultMode();\n else this.interactionManagerCapability?.activate('marqueeRedact');\n }\n\n private startRedaction() {\n this.interactionManagerCapability?.activate('redactSelection');\n }\n private endRedaction() {\n this.interactionManagerCapability?.activateDefaultMode();\n }\n\n public registerMarqueeOnPage(opts: RegisterMarqueeOnPageOptions) {\n if (!this.interactionManagerCapability) {\n this.logger.warn(\n 'RedactionPlugin',\n 'MissingDependency',\n 'Interaction manager plugin not loaded, marquee redaction disabled',\n );\n return () => {};\n }\n\n const document = this.coreState.core.document;\n if (!document) {\n this.logger.warn('RedactionPlugin', 'DocumentNotFound', 'Document not found');\n return () => {};\n }\n\n const page = document.pages[opts.pageIndex];\n if (!page) {\n this.logger.warn('RedactionPlugin', 'PageNotFound', `Page ${opts.pageIndex} not found`);\n return () => {};\n }\n\n const handlers = createMarqueeHandler({\n pageSize: page.size,\n scale: opts.scale,\n onPreview: opts.callback.onPreview,\n onCommit: (r) => {\n const item: RedactionItem = {\n id: uuidV4(),\n kind: 'area',\n page: opts.pageIndex,\n rect: r,\n };\n this.dispatch(addPending([item]));\n this.pending$.emit(this.state.pending);\n opts.callback.onCommit?.(r);\n this.enableRedactSelection();\n this.selectPending(opts.pageIndex, item.id);\n },\n });\n\n const off = this.interactionManagerCapability.registerAlways({\n handlers: {\n onPointerDown: (_, evt) => {\n if (evt.target === evt.currentTarget) {\n this.deselectPending();\n }\n },\n },\n scope: {\n type: 'page',\n pageIndex: opts.pageIndex,\n },\n });\n\n const off2 = this.interactionManagerCapability.registerHandlers({\n modeId: 'marqueeRedact',\n handlers,\n pageIndex: opts.pageIndex,\n });\n\n return () => {\n off();\n off2();\n };\n }\n\n private queueCurrentSelectionAsPending(): Task<boolean, PdfErrorReason> {\n if (!this.selectionCapability)\n return PdfTaskHelper.reject({\n code: PdfErrorCode.NotFound,\n message: '[RedactionPlugin] selection plugin required',\n });\n\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const formatted = this.selectionCapability.getFormattedSelection();\n if (!formatted.length) return PdfTaskHelper.resolve(true);\n\n const id = uuidV4();\n\n const items: RedactionItem[] = formatted.map((s) => ({\n id,\n kind: 'text',\n page: s.pageIndex,\n boundingRect: s.rect,\n rects: s.segmentRects,\n }));\n\n this.enableRedactSelection();\n this.dispatch(addPending(items));\n this.pending$.emit(this.state.pending);\n // optional: auto-select the last one added\n const last = items[items.length - 1];\n this.selectPending(last.page, last.id);\n\n // clear live UI selection\n this.redactionSelection$.emit([]);\n this.selectionCapability?.clear();\n\n return PdfTaskHelper.resolve(true);\n }\n\n private commitPendingOne(page: number, id: string): Task<boolean, PdfErrorReason> {\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const item = (this.state.pending[page] ?? []).find((it) => it.id === id);\n if (!item) return PdfTaskHelper.resolve(true);\n\n const rects: Rect[] = item.kind === 'text' ? item.rects : [item.rect];\n const pdfPage = doc.pages[page];\n if (!pdfPage)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Page not found' });\n\n const task = new Task<boolean, PdfErrorReason>();\n this.engine\n .redactTextInRects(doc, pdfPage, rects, {\n drawBlackBoxes: this.config.drawBlackBoxes,\n })\n .wait(\n () => {\n this.dispatch(removePending(page, id));\n this.pending$.emit(this.state.pending);\n this.dispatchCoreAction(refreshPages([page]));\n task.resolve(true);\n },\n () => task.reject({ code: PdfErrorCode.Unknown, message: 'Failed to commit redactions' }),\n );\n\n return task;\n }\n\n private commitAllPending(): Task<boolean, PdfErrorReason> {\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n // group rects per page\n const perPage = new Map<number, Rect[]>();\n for (const [page, items] of Object.entries(this.state.pending)) {\n const p = Number(page);\n const list = perPage.get(p) ?? [];\n for (const it of items) {\n if (it.kind === 'text') list.push(...it.rects);\n else list.push(it.rect);\n }\n perPage.set(p, list);\n }\n\n const pagesToRefresh = Array.from(perPage.entries())\n .filter(([_, rects]) => rects.length > 0)\n .map(([pageIndex]) => pageIndex);\n\n const tasks: PdfTask<boolean>[] = [];\n for (const [pageIndex, rects] of perPage) {\n const page = doc.pages[pageIndex];\n if (!page) continue;\n if (!rects.length) continue;\n tasks.push(\n this.engine.redactTextInRects(doc, page, rects, {\n drawBlackBoxes: this.config.drawBlackBoxes,\n }),\n );\n }\n\n const task = new Task<boolean, PdfErrorReason>();\n Task.all(tasks).wait(\n () => {\n this.dispatch(clearPending());\n this.dispatchCoreAction(refreshPages(pagesToRefresh));\n this.pending$.emit(this.state.pending);\n task.resolve(true);\n },\n () => task.reject({ code: PdfErrorCode.Unknown, message: 'Failed to commit redactions' }),\n );\n\n return task;\n }\n\n override onStoreUpdated(_: RedactionState, newState: RedactionState): void {\n // keep external listeners in sync\n this.pending$.emit(newState.pending);\n this.selected$.emit(newState.selected);\n }\n\n async destroy(): Promise<void> {\n this.redactionSelection$.clear();\n this.pending$.clear();\n\n this.unsubscribeSelectionChange?.();\n this.unsubscribeEndSelection?.();\n this.unsubscribeModeChange?.();\n\n await super.destroy();\n }\n}\n","import { Position, Rect, Size } from '@embedpdf/models';\nimport { clamp } from '@embedpdf/core';\nimport {\n EmbedPdfPointerEvent,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nexport function createMarqueeHandler(opts: {\n pageSize: Size;\n scale: number;\n minDragPx?: number;\n onPreview?: (rect: Rect | null) => void;\n onCommit?: (rect: Rect) => void;\n}): PointerEventHandlersWithLifecycle<EmbedPdfPointerEvent> {\n const { pageSize, scale, minDragPx = 5, onPreview, onCommit } = opts;\n\n let start: Position | null = null;\n let last: Rect | null = null;\n\n return {\n onPointerDown: (pos, evt) => {\n start = pos;\n last = { origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } };\n onPreview?.(last);\n evt.setPointerCapture?.();\n },\n onPointerMove: (pos) => {\n if (!start) return;\n const x = clamp(pos.x, 0, pageSize.width);\n const y = clamp(pos.y, 0, pageSize.height);\n last = {\n origin: { x: Math.min(start.x, x), y: Math.min(start.y, y) },\n size: { width: Math.abs(x - start.x), height: Math.abs(y - start.y) },\n };\n onPreview?.(last);\n },\n onPointerUp: (_pos, evt) => {\n if (last) {\n const dragPx = Math.max(last.size.width, last.size.height) * scale;\n if (dragPx > minDragPx) onCommit?.(last);\n }\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n onPointerCancel: (_pos, evt) => {\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n };\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { RedactionPluginConfig } from './types';\n\nexport const REDACTION_PLUGIN_ID = 'redaction';\n\nexport const manifest: PluginManifest<RedactionPluginConfig> = {\n id: REDACTION_PLUGIN_ID,\n name: 'Redaction Plugin',\n version: '1.0.0',\n provides: ['redaction'],\n requires: [],\n optional: ['interaction-manager', 'selection'],\n defaultConfig: {\n enabled: true,\n drawBlackBoxes: true,\n },\n};\n","import { RedactionState } from './types';\nimport {\n RedactionAction,\n ADD_PENDING,\n CLEAR_PENDING,\n END_REDACTION,\n REMOVE_PENDING,\n START_REDACTION,\n SELECT_PENDING,\n DESELECT_PENDING,\n} from './actions';\n\nexport const initialState: RedactionState = {\n isRedacting: false,\n pending: {},\n selected: null,\n};\n\nexport const redactionReducer = (state = initialState, action: RedactionAction): RedactionState => {\n switch (action.type) {\n case ADD_PENDING: {\n const next = { ...state.pending };\n for (const item of action.payload) {\n next[item.page] = (next[item.page] ?? []).concat(item);\n }\n return { ...state, pending: next };\n }\n\n case REMOVE_PENDING: {\n const { page, id } = action.payload;\n const list = state.pending[page] ?? [];\n const filtered = list.filter((it) => it.id !== id);\n const next = { ...state.pending, [page]: filtered };\n\n // if the removed one was selected → clear selection\n const stillSelected =\n state.selected && !(state.selected.page === page && state.selected.id === id);\n\n return { ...state, pending: next, selected: stillSelected ? state.selected : null };\n }\n\n case CLEAR_PENDING:\n return { ...state, pending: {}, selected: null };\n\n case SELECT_PENDING:\n return { ...state, selected: { page: action.payload.page, id: action.payload.id } };\n\n case DESELECT_PENDING:\n return { ...state, selected: null };\n\n case START_REDACTION:\n return { ...state, isRedacting: true };\n case END_REDACTION:\n return { ...state, pending: {}, selected: null, isRedacting: false };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { RedactionPluginConfig, RedactionState } from './types';\nimport { RedactionPlugin } from './redaction-plugin';\nimport { manifest, REDACTION_PLUGIN_ID } from './manifest';\nimport { RedactionAction } from './actions';\nimport { initialState, redactionReducer } from './reducer';\n\nexport const RedactionPluginPackage: PluginPackage<\n RedactionPlugin,\n RedactionPluginConfig,\n RedactionState,\n RedactionAction\n> = {\n manifest,\n create: (registry, config) => new RedactionPlugin(REDACTION_PLUGIN_ID, registry, config),\n reducer: redactionReducer,\n initialState: initialState,\n};\n\nexport * from './redaction-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './selectors';\n","import { RedactionState } from './types';\n\nexport const getPendingRedactionsCount = (s: RedactionState) =>\n Object.values(s.pending).reduce((sum, list) => sum + (list?.length ?? 0), 0);\n\nexport const hasPendingRedactions = (s: RedactionState) =>\n Object.values(s.pending).some((list) => (list?.length ?? 0) > 0);\n"],"names":["START_REDACTION","END_REDACTION","ADD_PENDING","REMOVE_PENDING","CLEAR_PENDING","SELECT_PENDING","DESELECT_PENDING","addPending","items","type","payload","removePending","page","id","clearPending","_RedactionPlugin","BasePlugin","constructor","registry","config","super","this","redactionSelection$","createBehaviorEmitter","pending$","selected$","selectionCapability","_a","getPlugin","provides","interactionManagerCapability","_b","registerMode","scope","exclusive","cursor","enableForMode","unsubscribeModeChange","_c","onModeChange","state","activeMode","dispatch","unsubscribeSelectionChange","_d","onSelectionChange","isRedacting","formattedSelection","getFormattedSelection","emit","unsubscribeEndSelection","_e","onEndSelection","map","s","uuidV4","kind","pageIndex","boundingRect","rect","rects","segmentRects","clear","pending","length","selectPending","initialize","_config","buildCapability","onRedactionSelectionChange","on","queueCurrentSelectionAsPending","enableMarqueeRedact","toggleMarqueeRedact","isMarqueeRedactActive","getActiveMode","enableRedactSelection","toggleRedactSelection","isRedactSelectionActive","onPendingChange","commitAllPending","commitPending","commitPendingOne","endRedaction","startRedaction","deselectPending","registerMarqueeOnPage","opts","selected","activate","activateDefaultMode","logger","warn","document","coreState","core","pages","handlers","pageSize","scale","minDragPx","onPreview","onCommit","start","last","onPointerDown","pos","evt","origin","x","y","size","width","height","setPointerCapture","call","onPointerMove","clamp","Math","min","abs","onPointerUp","_pos","max","releasePointerCapture","onPointerCancel","createMarqueeHandler","callback","r","item","off","registerAlways","_","target","currentTarget","off2","registerHandlers","modeId","PdfTaskHelper","reject","code","PdfErrorCode","NotFound","message","formatted","resolve","doc","find","it","pdfPage","task","Task","engine","redactTextInRects","drawBlackBoxes","wait","dispatchCoreAction","refreshPages","Unknown","perPage","Map","Object","entries","p","Number","list","get","push","set","pagesToRefresh","Array","from","filter","tasks","all","onStoreUpdated","newState","destroy","RedactionPlugin","REDACTION_PLUGIN_ID","manifest","name","version","requires","optional","defaultConfig","enabled","initialState","RedactionPluginPackage","create","reducer","action","next","concat","filtered","stillSelected","values","reduce","sum","some"],"mappings":"gJAGaA,EAAkB,kBAClBC,EAAgB,gBAEhBC,EAAc,cACdC,EAAiB,iBACjBC,EAAgB,gBAEhBC,EAAiB,iBACjBC,EAAmB,mBAsCnBC,EAAcC,IAA8C,CACvEC,KAAMP,EACNQ,QAASF,IAEEG,EAAgB,CAACC,EAAcC,KAAqC,CAC/EJ,KAAMN,EACNO,QAAS,CAAEE,OAAMC,QAENC,EAAe,KAAA,CAA6BL,KAAML,ICVxD,MAAMW,EAAN,cAA8BC,EAAAA,WAmBnC,WAAAC,CAAYJ,EAAYK,EAA0BC,iBAChDC,MAAMP,EAAIK,GATKG,KAAAC,oBAAsBC,0BACtBF,KAAAG,SAAWD,0BACXF,KAAAI,UAAYF,0BAQ3BF,KAAKF,OAASA,EAEdE,KAAKK,oBAAsB,OAAAC,EAAKN,KAAAH,SAASU,UAA2B,mBAAc,EAAAD,EAAAE,WAClFR,KAAKS,6BAA+B,OAAAC,EAAKV,KAAAH,SACtCU,UAAoC,6BACnC,EAAAG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S,CAAA,EAAIyB,SAAU,MAE5C,KAAKnF,EACH,MAAO,IAAKmC,EAAOgD,SAAU,CAAE5E,KAAMmL,EAAOrL,QAAQE,KAAMC,GAAIkL,EAAOrL,QAAQG,KAE/E,KAAKP,EACH,MAAO,IAAKkC,EAAOgD,SAAU,MAE/B,KAAKxF,EACH,MAAO,IAAKwC,EAAOM,aAAa,GAClC,KAAK7C,EACI,MAAA,IAAKuC,EAAOuB,QAAS,CAAA,EAAIyB,SAAU,KAAM1C,aAAa,GAC/D,QACS,OAAAN,EAAA,ECvCXmJ,2ICdwCrI,GACxC2G,OAAOmC,OAAO9I,EAAES,SAASsI,QAAO,CAACC,EAAKjC,IAASiC,IAAa,MAANjC,OAAM,EAAAA,EAAArG,SAAU,IAAI,gCAEvCV,GACnC2G,OAAOmC,OAAO9I,EAAES,SAASwI,MAAMlC,KAAgB,MAANA,OAAM,EAAAA,EAAArG,SAAU,GAAK"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/types.ts","../src/lib/actions.ts","../src/lib/redaction-plugin.ts","../src/lib/handlers/marquee-redact.handler.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts","../src/lib/selectors.ts"],"sourcesContent":["import { BasePluginConfig, EventHook } from '@embedpdf/core';\nimport { PdfErrorReason, Rect, Task } from '@embedpdf/models';\n\n// Redaction mode enum\nexport enum RedactionMode {\n MarqueeRedact = 'marqueeRedact',\n RedactSelection = 'redactSelection',\n}\n\nexport interface SelectedRedaction {\n page: number;\n id: string | null;\n}\n\nexport interface RedactionState {\n isRedacting: boolean;\n activeType: RedactionMode | null;\n pending: Record<number, RedactionItem[]>;\n pendingCount: number;\n selected: SelectedRedaction | null;\n}\n\nexport type RedactionItem =\n | {\n id: string;\n kind: 'text';\n page: number;\n rect: Rect;\n rects: Rect[];\n }\n | {\n id: string;\n kind: 'area';\n page: number;\n rect: Rect;\n };\n\nexport interface MarqueeRedactCallback {\n onPreview?: (rect: Rect | null) => void;\n onCommit?: (rect: Rect) => void;\n}\n\nexport interface RegisterMarqueeOnPageOptions {\n pageIndex: number;\n scale: number;\n callback: MarqueeRedactCallback;\n}\n\nexport interface RedactionPluginConfig extends BasePluginConfig {\n drawBlackBoxes: boolean;\n}\n\n// Add event types similar to annotation plugin\nexport type RedactionEvent =\n | {\n type: 'add';\n items: RedactionItem[];\n }\n | {\n type: 'remove';\n page: number;\n id: string;\n }\n | {\n type: 'clear';\n }\n | {\n type: 'commit';\n success: boolean;\n error?: PdfErrorReason;\n };\n\nexport interface RedactionCapability {\n queueCurrentSelectionAsPending: () => Task<boolean, PdfErrorReason>;\n\n enableMarqueeRedact: () => void;\n toggleMarqueeRedact: () => void;\n isMarqueeRedactActive: () => boolean;\n\n enableRedactSelection: () => void;\n toggleRedactSelection: () => void;\n isRedactSelectionActive: () => boolean;\n\n onPendingChange: EventHook<Record<number, RedactionItem[]>>;\n addPending: (items: RedactionItem[]) => void;\n removePending: (page: number, id: string) => void;\n clearPending: () => void;\n commitAllPending: () => Task<boolean, PdfErrorReason>;\n commitPending: (page: number, id: string) => Task<boolean, PdfErrorReason>;\n\n endRedaction: () => void;\n startRedaction: () => void;\n\n selectPending: (page: number, id: string) => void;\n deselectPending: () => void;\n\n // Event hook for redaction events\n onSelectedChange: EventHook<SelectedRedaction | null>;\n onRedactionEvent: EventHook<RedactionEvent>;\n onStateChange: EventHook<RedactionState>;\n}\n","import { Action } from '@embedpdf/core';\nimport { RedactionItem, RedactionMode } from './types';\n\nexport const START_REDACTION = 'START_REDACTION';\nexport const END_REDACTION = 'END_REDACTION';\nexport const SET_ACTIVE_TYPE = 'SET_ACTIVE_TYPE';\n\nexport const ADD_PENDING = 'ADD_PENDING';\nexport const REMOVE_PENDING = 'REMOVE_PENDING';\nexport const CLEAR_PENDING = 'CLEAR_PENDING';\n\nexport const SELECT_PENDING = 'SELECT_PENDING';\nexport const DESELECT_PENDING = 'DESELECT_PENDING';\n\nexport interface StartRedactionAction extends Action {\n type: typeof START_REDACTION;\n payload: RedactionMode;\n}\nexport interface EndRedactionAction extends Action {\n type: typeof END_REDACTION;\n}\nexport interface SetActiveTypeAction extends Action {\n type: typeof SET_ACTIVE_TYPE;\n payload: RedactionMode | null;\n}\n\nexport interface AddPendingAction extends Action {\n type: typeof ADD_PENDING;\n payload: RedactionItem[];\n}\nexport interface RemovePendingAction extends Action {\n type: typeof REMOVE_PENDING;\n payload: { page: number; id: string };\n}\nexport interface ClearPendingAction extends Action {\n type: typeof CLEAR_PENDING;\n}\n\nexport interface SelectPendingAction extends Action {\n type: typeof SELECT_PENDING;\n payload: { page: number; id: string };\n}\nexport interface DeselectPendingAction extends Action {\n type: typeof DESELECT_PENDING;\n}\n\nexport type RedactionAction =\n | StartRedactionAction\n | EndRedactionAction\n | SetActiveTypeAction\n | AddPendingAction\n | RemovePendingAction\n | ClearPendingAction\n | SelectPendingAction\n | DeselectPendingAction;\n\nexport const addPending = (items: RedactionItem[]): AddPendingAction => ({\n type: ADD_PENDING,\n payload: items,\n});\nexport const removePending = (page: number, id: string): RemovePendingAction => ({\n type: REMOVE_PENDING,\n payload: { page, id },\n});\nexport const clearPending = (): ClearPendingAction => ({ type: CLEAR_PENDING });\n\nexport const startRedaction = (mode: RedactionMode): StartRedactionAction => ({\n type: START_REDACTION,\n payload: mode,\n});\nexport const endRedaction = (): EndRedactionAction => ({ type: END_REDACTION });\nexport const setActiveType = (mode: RedactionMode | null): SetActiveTypeAction => ({\n type: SET_ACTIVE_TYPE,\n payload: mode,\n});\n\nexport const selectPending = (page: number, id: string): SelectPendingAction => ({\n type: SELECT_PENDING,\n payload: { page, id },\n});\nexport const deselectPending = (): DeselectPendingAction => ({ type: DESELECT_PENDING });\n","import {\n RedactionPluginConfig,\n RedactionCapability,\n RedactionState,\n RegisterMarqueeOnPageOptions,\n RedactionItem,\n SelectedRedaction,\n RedactionMode,\n RedactionEvent,\n} from './types';\nimport {\n BasePlugin,\n createBehaviorEmitter,\n PluginRegistry,\n refreshPages,\n Unsubscribe,\n} from '@embedpdf/core';\nimport {\n PdfErrorCode,\n PdfErrorReason,\n PdfTask,\n PdfTaskHelper,\n Rect,\n Task,\n uuidV4,\n} from '@embedpdf/models';\nimport {\n FormattedSelection,\n SelectionCapability,\n SelectionPlugin,\n} from '@embedpdf/plugin-selection';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport {\n addPending,\n clearPending,\n deselectPending,\n endRedaction,\n removePending,\n selectPending,\n startRedaction,\n} from './actions';\nimport { createMarqueeHandler } from './handlers';\n\nexport class RedactionPlugin extends BasePlugin<\n RedactionPluginConfig,\n RedactionCapability,\n RedactionState\n> {\n static readonly id = 'redaction' as const;\n private config: RedactionPluginConfig;\n\n private selectionCapability: SelectionCapability | undefined;\n private interactionManagerCapability: InteractionManagerCapability | undefined;\n\n private readonly redactionSelection$ = createBehaviorEmitter<FormattedSelection[]>();\n private readonly pending$ = createBehaviorEmitter<Record<number, RedactionItem[]>>();\n private readonly selected$ = createBehaviorEmitter<SelectedRedaction | null>();\n private readonly state$ = createBehaviorEmitter<RedactionState>();\n private readonly events$ = createBehaviorEmitter<RedactionEvent>();\n\n private readonly unsubscribeSelectionChange: Unsubscribe | undefined;\n private readonly unsubscribeEndSelection: Unsubscribe | undefined;\n private readonly unsubscribeModeChange: Unsubscribe | undefined;\n\n constructor(id: string, registry: PluginRegistry, config: RedactionPluginConfig) {\n super(id, registry);\n this.config = config;\n\n this.selectionCapability = this.registry.getPlugin<SelectionPlugin>('selection')?.provides();\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')\n ?.provides();\n\n if (this.interactionManagerCapability) {\n this.interactionManagerCapability.registerMode({\n id: RedactionMode.MarqueeRedact,\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\n }\n\n if (this.interactionManagerCapability && this.selectionCapability) {\n this.interactionManagerCapability.registerMode({\n id: RedactionMode.RedactSelection,\n scope: 'page',\n exclusive: false,\n });\n this.selectionCapability.enableForMode(RedactionMode.RedactSelection);\n }\n\n this.unsubscribeModeChange = this.interactionManagerCapability?.onModeChange((state) => {\n if (state.activeMode === RedactionMode.RedactSelection) {\n this.dispatch(startRedaction(RedactionMode.RedactSelection));\n } else if (state.activeMode === RedactionMode.MarqueeRedact) {\n this.dispatch(startRedaction(RedactionMode.MarqueeRedact));\n } else {\n this.dispatch(endRedaction());\n }\n });\n\n this.unsubscribeSelectionChange = this.selectionCapability?.onSelectionChange(() => {\n if (!this.selectionCapability) return;\n if (!this.state.isRedacting) return;\n const formattedSelection = this.selectionCapability.getFormattedSelection();\n this.redactionSelection$.emit(formattedSelection);\n });\n\n this.unsubscribeEndSelection = this.selectionCapability?.onEndSelection(() => {\n if (!this.selectionCapability) return;\n if (!this.state.isRedacting) return;\n\n const formattedSelection = this.selectionCapability.getFormattedSelection();\n\n const items: RedactionItem[] = formattedSelection.map((s) => ({\n id: uuidV4(),\n kind: 'text',\n page: s.pageIndex,\n rect: s.rect,\n rects: s.segmentRects,\n }));\n\n this.dispatch(addPending(items));\n this.redactionSelection$.emit([]);\n this.selectionCapability.clear();\n this.pending$.emit(this.state.pending);\n if (items.length) {\n this.selectPending(items[items.length - 1].page, items[items.length - 1].id);\n }\n });\n }\n\n async initialize(_config: RedactionPluginConfig): Promise<void> {}\n\n protected buildCapability(): RedactionCapability {\n return {\n queueCurrentSelectionAsPending: () => this.queueCurrentSelectionAsPending(),\n\n enableMarqueeRedact: () => this.enableMarqueeRedact(),\n toggleMarqueeRedact: () => this.toggleMarqueeRedact(),\n isMarqueeRedactActive: () =>\n this.interactionManagerCapability?.getActiveMode() === RedactionMode.MarqueeRedact,\n\n enableRedactSelection: () => this.enableRedactSelection(),\n toggleRedactSelection: () => this.toggleRedactSelection(),\n isRedactSelectionActive: () =>\n this.interactionManagerCapability?.getActiveMode() === RedactionMode.RedactSelection,\n\n addPending: (items) => {\n this.dispatch(addPending(items));\n this.pending$.emit(this.state.pending);\n this.events$.emit({ type: 'add', items });\n },\n removePending: (page, id) => {\n this.dispatch(removePending(page, id));\n this.pending$.emit(this.state.pending);\n this.events$.emit({ type: 'remove', page, id });\n },\n clearPending: () => {\n this.dispatch(clearPending());\n this.pending$.emit(this.state.pending);\n this.events$.emit({ type: 'clear' });\n },\n commitAllPending: () => this.commitAllPending(),\n commitPending: (page, id) => this.commitPendingOne(page, id),\n\n endRedaction: () => this.endRedaction(),\n startRedaction: () => this.startRedaction(),\n\n selectPending: (page, id) => this.selectPending(page, id),\n deselectPending: () => this.deselectPending(),\n\n onSelectedChange: this.selected$.on,\n onRedactionEvent: this.events$.on,\n onStateChange: this.state$.on,\n onPendingChange: this.pending$.on,\n };\n }\n\n public onRedactionSelectionChange(\n callback: (formattedSelection: FormattedSelection[]) => void,\n ): Unsubscribe {\n return this.redactionSelection$.on(callback);\n }\n\n private selectPending(page: number, id: string) {\n this.dispatch(selectPending(page, id));\n this.selectionCapability?.clear();\n this.selected$.emit(this.state.selected);\n }\n private deselectPending() {\n this.dispatch(deselectPending());\n this.selected$.emit(this.state.selected);\n }\n\n private enableRedactSelection() {\n this.interactionManagerCapability?.activate(RedactionMode.RedactSelection);\n }\n private toggleRedactSelection() {\n if (this.interactionManagerCapability?.getActiveMode() === RedactionMode.RedactSelection)\n this.interactionManagerCapability?.activateDefaultMode();\n else this.interactionManagerCapability?.activate(RedactionMode.RedactSelection);\n }\n\n private enableMarqueeRedact() {\n this.interactionManagerCapability?.activate(RedactionMode.MarqueeRedact);\n }\n private toggleMarqueeRedact() {\n if (this.interactionManagerCapability?.getActiveMode() === RedactionMode.MarqueeRedact)\n this.interactionManagerCapability?.activateDefaultMode();\n else this.interactionManagerCapability?.activate(RedactionMode.MarqueeRedact);\n }\n\n private startRedaction() {\n this.interactionManagerCapability?.activate(RedactionMode.RedactSelection);\n }\n private endRedaction() {\n this.interactionManagerCapability?.activateDefaultMode();\n }\n\n public registerMarqueeOnPage(opts: RegisterMarqueeOnPageOptions) {\n if (!this.interactionManagerCapability) {\n this.logger.warn(\n 'RedactionPlugin',\n 'MissingDependency',\n 'Interaction manager plugin not loaded, marquee redaction disabled',\n );\n return () => {};\n }\n\n const document = this.coreState.core.document;\n if (!document) {\n this.logger.warn('RedactionPlugin', 'DocumentNotFound', 'Document not found');\n return () => {};\n }\n\n const page = document.pages[opts.pageIndex];\n if (!page) {\n this.logger.warn('RedactionPlugin', 'PageNotFound', `Page ${opts.pageIndex} not found`);\n return () => {};\n }\n\n const handlers = createMarqueeHandler({\n pageSize: page.size,\n scale: opts.scale,\n onPreview: opts.callback.onPreview,\n onCommit: (r) => {\n const item: RedactionItem = {\n id: uuidV4(),\n kind: 'area',\n page: opts.pageIndex,\n rect: r,\n };\n this.dispatch(addPending([item]));\n this.pending$.emit(this.state.pending);\n opts.callback.onCommit?.(r);\n this.enableRedactSelection();\n this.selectPending(opts.pageIndex, item.id);\n },\n });\n\n const off = this.interactionManagerCapability.registerAlways({\n handlers: {\n onPointerDown: (_, evt) => {\n if (evt.target === evt.currentTarget) {\n this.deselectPending();\n }\n },\n },\n scope: {\n type: 'page',\n pageIndex: opts.pageIndex,\n },\n });\n\n const off2 = this.interactionManagerCapability.registerHandlers({\n modeId: RedactionMode.MarqueeRedact,\n handlers,\n pageIndex: opts.pageIndex,\n });\n\n return () => {\n off();\n off2();\n };\n }\n\n private queueCurrentSelectionAsPending(): Task<boolean, PdfErrorReason> {\n if (!this.selectionCapability)\n return PdfTaskHelper.reject({\n code: PdfErrorCode.NotFound,\n message: '[RedactionPlugin] selection plugin required',\n });\n\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const formatted = this.selectionCapability.getFormattedSelection();\n if (!formatted.length) return PdfTaskHelper.resolve(true);\n\n const id = uuidV4();\n\n const items: RedactionItem[] = formatted.map((s) => ({\n id,\n kind: 'text',\n page: s.pageIndex,\n rect: s.rect,\n rects: s.segmentRects,\n }));\n\n this.enableRedactSelection();\n this.dispatch(addPending(items));\n this.pending$.emit(this.state.pending);\n // optional: auto-select the last one added\n const last = items[items.length - 1];\n this.selectPending(last.page, last.id);\n\n // clear live UI selection\n this.redactionSelection$.emit([]);\n this.selectionCapability?.clear();\n\n return PdfTaskHelper.resolve(true);\n }\n\n private commitPendingOne(page: number, id: string): Task<boolean, PdfErrorReason> {\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const item = (this.state.pending[page] ?? []).find((it) => it.id === id);\n if (!item) return PdfTaskHelper.resolve(true);\n\n const rects: Rect[] = item.kind === 'text' ? item.rects : [item.rect];\n const pdfPage = doc.pages[page];\n if (!pdfPage)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Page not found' });\n\n const task = new Task<boolean, PdfErrorReason>();\n this.engine\n .redactTextInRects(doc, pdfPage, rects, {\n drawBlackBoxes: this.config.drawBlackBoxes,\n })\n .wait(\n () => {\n this.dispatch(removePending(page, id));\n this.pending$.emit(this.state.pending);\n this.dispatchCoreAction(refreshPages([page]));\n this.events$.emit({ type: 'commit', success: true });\n task.resolve(true);\n },\n (error) => {\n this.events$.emit({ type: 'commit', success: false, error: error.reason });\n task.reject({ code: PdfErrorCode.Unknown, message: 'Failed to commit redactions' });\n },\n );\n\n return task;\n }\n\n private commitAllPending(): Task<boolean, PdfErrorReason> {\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n // group rects per page\n const perPage = new Map<number, Rect[]>();\n for (const [page, items] of Object.entries(this.state.pending)) {\n const p = Number(page);\n const list = perPage.get(p) ?? [];\n for (const it of items) {\n if (it.kind === 'text') list.push(...it.rects);\n else list.push(it.rect);\n }\n perPage.set(p, list);\n }\n\n const pagesToRefresh = Array.from(perPage.entries())\n .filter(([_, rects]) => rects.length > 0)\n .map(([pageIndex]) => pageIndex);\n\n const tasks: PdfTask<boolean>[] = [];\n for (const [pageIndex, rects] of perPage) {\n const page = doc.pages[pageIndex];\n if (!page) continue;\n if (!rects.length) continue;\n tasks.push(\n this.engine.redactTextInRects(doc, page, rects, {\n drawBlackBoxes: this.config.drawBlackBoxes,\n }),\n );\n }\n\n const task = new Task<boolean, PdfErrorReason>();\n Task.all(tasks).wait(\n () => {\n this.dispatch(clearPending());\n this.dispatchCoreAction(refreshPages(pagesToRefresh));\n this.pending$.emit(this.state.pending);\n this.events$.emit({ type: 'commit', success: true });\n task.resolve(true);\n },\n (error) => {\n this.events$.emit({ type: 'commit', success: false, error: error.reason });\n task.reject({ code: PdfErrorCode.Unknown, message: 'Failed to commit redactions' });\n },\n );\n\n return task;\n }\n\n override onStoreUpdated(_: RedactionState, newState: RedactionState): void {\n // keep external listeners in sync\n this.pending$.emit(newState.pending);\n this.selected$.emit(newState.selected);\n this.state$.emit(newState);\n }\n\n async destroy(): Promise<void> {\n this.redactionSelection$.clear();\n this.pending$.clear();\n this.state$.clear();\n this.events$.clear();\n\n this.unsubscribeSelectionChange?.();\n this.unsubscribeEndSelection?.();\n this.unsubscribeModeChange?.();\n\n await super.destroy();\n }\n}\n","import { Position, Rect, Size } from '@embedpdf/models';\nimport { clamp } from '@embedpdf/core';\nimport {\n EmbedPdfPointerEvent,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nexport function createMarqueeHandler(opts: {\n pageSize: Size;\n scale: number;\n minDragPx?: number;\n onPreview?: (rect: Rect | null) => void;\n onCommit?: (rect: Rect) => void;\n}): PointerEventHandlersWithLifecycle<EmbedPdfPointerEvent> {\n const { pageSize, scale, minDragPx = 5, onPreview, onCommit } = opts;\n\n let start: Position | null = null;\n let last: Rect | null = null;\n\n return {\n onPointerDown: (pos, evt) => {\n start = pos;\n last = { origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } };\n onPreview?.(last);\n evt.setPointerCapture?.();\n },\n onPointerMove: (pos) => {\n if (!start) return;\n const x = clamp(pos.x, 0, pageSize.width);\n const y = clamp(pos.y, 0, pageSize.height);\n last = {\n origin: { x: Math.min(start.x, x), y: Math.min(start.y, y) },\n size: { width: Math.abs(x - start.x), height: Math.abs(y - start.y) },\n };\n onPreview?.(last);\n },\n onPointerUp: (_pos, evt) => {\n if (last) {\n const dragPx = Math.max(last.size.width, last.size.height) * scale;\n if (dragPx > minDragPx) onCommit?.(last);\n }\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n onPointerCancel: (_pos, evt) => {\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n };\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { RedactionPluginConfig } from './types';\n\nexport const REDACTION_PLUGIN_ID = 'redaction';\n\nexport const manifest: PluginManifest<RedactionPluginConfig> = {\n id: REDACTION_PLUGIN_ID,\n name: 'Redaction Plugin',\n version: '1.0.0',\n provides: ['redaction'],\n requires: [],\n optional: ['interaction-manager', 'selection'],\n defaultConfig: {\n enabled: true,\n drawBlackBoxes: true,\n },\n};\n","import { RedactionItem, RedactionState } from './types';\nimport {\n RedactionAction,\n ADD_PENDING,\n CLEAR_PENDING,\n END_REDACTION,\n REMOVE_PENDING,\n START_REDACTION,\n SET_ACTIVE_TYPE,\n SELECT_PENDING,\n DESELECT_PENDING,\n} from './actions';\n\n// Helper function to calculate total pending count\nconst calculatePendingCount = (pending: Record<number, RedactionItem[]>): number => {\n return Object.values(pending).reduce((total, items) => total + items.length, 0);\n};\n\nexport const initialState: RedactionState = {\n isRedacting: false,\n activeType: null,\n pending: {},\n pendingCount: 0,\n selected: null,\n};\n\nexport const redactionReducer = (state = initialState, action: RedactionAction): RedactionState => {\n switch (action.type) {\n case ADD_PENDING: {\n const next = { ...state.pending };\n for (const item of action.payload) {\n next[item.page] = (next[item.page] ?? []).concat(item);\n }\n return { ...state, pending: next, pendingCount: calculatePendingCount(next) };\n }\n\n case REMOVE_PENDING: {\n const { page, id } = action.payload;\n const list = state.pending[page] ?? [];\n const filtered = list.filter((it) => it.id !== id);\n const next = { ...state.pending, [page]: filtered };\n\n // if the removed one was selected → clear selection\n const stillSelected =\n state.selected && !(state.selected.page === page && state.selected.id === id);\n\n return {\n ...state,\n pending: next,\n pendingCount: calculatePendingCount(next),\n selected: stillSelected ? state.selected : null,\n };\n }\n\n case CLEAR_PENDING:\n return { ...state, pending: {}, pendingCount: 0, selected: null };\n\n case SELECT_PENDING:\n return { ...state, selected: { page: action.payload.page, id: action.payload.id } };\n\n case DESELECT_PENDING:\n return { ...state, selected: null };\n\n case START_REDACTION:\n return { ...state, isRedacting: true, activeType: action.payload };\n case END_REDACTION:\n return {\n ...state,\n pending: {},\n pendingCount: 0,\n selected: null,\n isRedacting: false,\n activeType: null,\n };\n case SET_ACTIVE_TYPE:\n return { ...state, activeType: action.payload };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { RedactionPluginConfig, RedactionState } from './types';\nimport { RedactionPlugin } from './redaction-plugin';\nimport { manifest, REDACTION_PLUGIN_ID } from './manifest';\nimport { RedactionAction } from './actions';\nimport { initialState, redactionReducer } from './reducer';\n\nexport const RedactionPluginPackage: PluginPackage<\n RedactionPlugin,\n RedactionPluginConfig,\n RedactionState,\n RedactionAction\n> = {\n manifest,\n create: (registry, config) => new RedactionPlugin(REDACTION_PLUGIN_ID, registry, config),\n reducer: redactionReducer,\n initialState: initialState,\n};\n\nexport * from './redaction-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './selectors';\nexport { initialState } from './reducer';\n","import { RedactionState } from './types';\n\nexport const getPendingRedactionsCount = (s: RedactionState) =>\n Object.values(s.pending).reduce((sum, list) => sum + (list?.length ?? 0), 0);\n\nexport const hasPendingRedactions = (s: RedactionState) =>\n Object.values(s.pending).some((list) => (list?.length ?? 0) > 0);\n"],"names":["RedactionMode","START_REDACTION","END_REDACTION","ADD_PENDING","REMOVE_PENDING","CLEAR_PENDING","SELECT_PENDING","DESELECT_PENDING","addPending","items","type","payload","removePending","page","id","clearPending","startRedaction","mode","_RedactionPlugin","BasePlugin","constructor","registry","config","super","this","redactionSelection$","createBehaviorEmitter","pending$","selected$","state$","events$","selectionCapability","_a","getPlugin","provides","interactionManagerCapability","_b","registerMode","MarqueeRedact","scope","exclusive","cursor","RedactSelection","enableForMode","unsubscribeModeChange","_c","onModeChange","state","activeMode","dispatch","unsubscribeSelectionChange","_d","onSelectionChange","isRedacting","formattedSelection","getFormattedSelection","emit","unsubscribeEndSelection","_e","onEndSelection","map","s","uuidV4","kind","pageIndex","rect","rects","segmentRects","clear","pending","length","selectPending","initialize","_config","buildCapability","queueCurrentSelectionAsPending","enableMarqueeRedact","toggleMarqueeRedact","isMarqueeRedactActive","getActiveMode","enableRedactSelection","toggleRedactSelection","isRedactSelectionActive","commitAllPending","commitPending","commitPendingOne","endRedaction","deselectPending","onSelectedChange","on","onRedactionEvent","onStateChange","onPendingChange","onRedactionSelectionChange","callback","selected","activate","activateDefaultMode","registerMarqueeOnPage","opts","logger","warn","document","coreState","core","pages","handlers","pageSize","scale","minDragPx","onPreview","onCommit","start","last","onPointerDown","pos","evt","origin","x","y","size","width","height","setPointerCapture","call","onPointerMove","clamp","Math","min","abs","onPointerUp","_pos","max","releasePointerCapture","onPointerCancel","createMarqueeHandler","r","item","off","registerAlways","_","target","currentTarget","off2","registerHandlers","modeId","PdfTaskHelper","reject","code","PdfErrorCode","NotFound","message","formatted","resolve","doc","find","it","pdfPage","task","Task","engine","redactTextInRects","drawBlackBoxes","wait","dispatchCoreAction","refreshPages","success","error","reason","Unknown","perPage","Map","Object","entries","p","Number","list","get","push","set","pagesToRefresh","Array","from","filter","tasks","all","onStoreUpdated","newState","destroy","RedactionPlugin","REDACTION_PLUGIN_ID","manifest","name","version","requires","optional","defaultConfig","enabled","calculatePendingCount","values","reduce","total","initialState","activeType","pendingCount","RedactionPluginPackage","create","reducer","action","next","concat","filtered","stillSelected","sum","some"],"mappings":"gJAIY,IAAAA,GAAAA,IACVA,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1I,EAAEQ,SAASiJ,MAAMtC,KAAgB,MAANA,OAAM,EAAAA,EAAA1G,SAAU,GAAK"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { clamp, BasePlugin, createBehaviorEmitter, refreshPages } from "@embedpdf/core";
|
|
2
2
|
import { uuidV4, PdfTaskHelper, PdfErrorCode, Task } from "@embedpdf/models";
|
|
3
|
+
var RedactionMode = /* @__PURE__ */ ((RedactionMode2) => {
|
|
4
|
+
RedactionMode2["MarqueeRedact"] = "marqueeRedact";
|
|
5
|
+
RedactionMode2["RedactSelection"] = "redactSelection";
|
|
6
|
+
return RedactionMode2;
|
|
7
|
+
})(RedactionMode || {});
|
|
3
8
|
const START_REDACTION = "START_REDACTION";
|
|
4
9
|
const END_REDACTION = "END_REDACTION";
|
|
10
|
+
const SET_ACTIVE_TYPE = "SET_ACTIVE_TYPE";
|
|
5
11
|
const ADD_PENDING = "ADD_PENDING";
|
|
6
12
|
const REMOVE_PENDING = "REMOVE_PENDING";
|
|
7
13
|
const CLEAR_PENDING = "CLEAR_PENDING";
|
|
@@ -16,7 +22,10 @@ const removePending = (page, id) => ({
|
|
|
16
22
|
payload: { page, id }
|
|
17
23
|
});
|
|
18
24
|
const clearPending = () => ({ type: CLEAR_PENDING });
|
|
19
|
-
const startRedaction = () => ({
|
|
25
|
+
const startRedaction = (mode) => ({
|
|
26
|
+
type: START_REDACTION,
|
|
27
|
+
payload: mode
|
|
28
|
+
});
|
|
20
29
|
const endRedaction = () => ({ type: END_REDACTION });
|
|
21
30
|
const selectPending = (page, id) => ({
|
|
22
31
|
type: SELECT_PENDING,
|
|
@@ -72,12 +81,14 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
72
81
|
this.redactionSelection$ = createBehaviorEmitter();
|
|
73
82
|
this.pending$ = createBehaviorEmitter();
|
|
74
83
|
this.selected$ = createBehaviorEmitter();
|
|
84
|
+
this.state$ = createBehaviorEmitter();
|
|
85
|
+
this.events$ = createBehaviorEmitter();
|
|
75
86
|
this.config = config;
|
|
76
87
|
this.selectionCapability = (_a = this.registry.getPlugin("selection")) == null ? void 0 : _a.provides();
|
|
77
88
|
this.interactionManagerCapability = (_b = this.registry.getPlugin("interaction-manager")) == null ? void 0 : _b.provides();
|
|
78
89
|
if (this.interactionManagerCapability) {
|
|
79
90
|
this.interactionManagerCapability.registerMode({
|
|
80
|
-
id:
|
|
91
|
+
id: RedactionMode.MarqueeRedact,
|
|
81
92
|
scope: "page",
|
|
82
93
|
exclusive: true,
|
|
83
94
|
cursor: "crosshair"
|
|
@@ -85,16 +96,20 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
85
96
|
}
|
|
86
97
|
if (this.interactionManagerCapability && this.selectionCapability) {
|
|
87
98
|
this.interactionManagerCapability.registerMode({
|
|
88
|
-
id:
|
|
99
|
+
id: RedactionMode.RedactSelection,
|
|
89
100
|
scope: "page",
|
|
90
101
|
exclusive: false
|
|
91
102
|
});
|
|
92
|
-
this.selectionCapability.enableForMode(
|
|
103
|
+
this.selectionCapability.enableForMode(RedactionMode.RedactSelection);
|
|
93
104
|
}
|
|
94
105
|
this.unsubscribeModeChange = (_c = this.interactionManagerCapability) == null ? void 0 : _c.onModeChange((state) => {
|
|
95
|
-
if (state.activeMode ===
|
|
96
|
-
this.dispatch(startRedaction());
|
|
97
|
-
else
|
|
106
|
+
if (state.activeMode === RedactionMode.RedactSelection) {
|
|
107
|
+
this.dispatch(startRedaction(RedactionMode.RedactSelection));
|
|
108
|
+
} else if (state.activeMode === RedactionMode.MarqueeRedact) {
|
|
109
|
+
this.dispatch(startRedaction(RedactionMode.MarqueeRedact));
|
|
110
|
+
} else {
|
|
111
|
+
this.dispatch(endRedaction());
|
|
112
|
+
}
|
|
98
113
|
});
|
|
99
114
|
this.unsubscribeSelectionChange = (_d = this.selectionCapability) == null ? void 0 : _d.onSelectionChange(() => {
|
|
100
115
|
if (!this.selectionCapability) return;
|
|
@@ -110,7 +125,7 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
110
125
|
id: uuidV4(),
|
|
111
126
|
kind: "text",
|
|
112
127
|
page: s.pageIndex,
|
|
113
|
-
|
|
128
|
+
rect: s.rect,
|
|
114
129
|
rects: s.segmentRects
|
|
115
130
|
}));
|
|
116
131
|
this.dispatch(addPending(items));
|
|
@@ -126,39 +141,49 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
126
141
|
}
|
|
127
142
|
buildCapability() {
|
|
128
143
|
return {
|
|
129
|
-
onRedactionSelectionChange: this.redactionSelection$.on,
|
|
130
144
|
queueCurrentSelectionAsPending: () => this.queueCurrentSelectionAsPending(),
|
|
131
145
|
enableMarqueeRedact: () => this.enableMarqueeRedact(),
|
|
132
146
|
toggleMarqueeRedact: () => this.toggleMarqueeRedact(),
|
|
133
147
|
isMarqueeRedactActive: () => {
|
|
134
148
|
var _a;
|
|
135
|
-
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) ===
|
|
149
|
+
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === RedactionMode.MarqueeRedact;
|
|
136
150
|
},
|
|
137
151
|
enableRedactSelection: () => this.enableRedactSelection(),
|
|
138
152
|
toggleRedactSelection: () => this.toggleRedactSelection(),
|
|
139
153
|
isRedactSelectionActive: () => {
|
|
140
154
|
var _a;
|
|
141
|
-
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) ===
|
|
155
|
+
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === RedactionMode.RedactSelection;
|
|
156
|
+
},
|
|
157
|
+
addPending: (items) => {
|
|
158
|
+
this.dispatch(addPending(items));
|
|
159
|
+
this.pending$.emit(this.state.pending);
|
|
160
|
+
this.events$.emit({ type: "add", items });
|
|
142
161
|
},
|
|
143
|
-
onPendingChange: this.pending$.on,
|
|
144
162
|
removePending: (page, id) => {
|
|
145
163
|
this.dispatch(removePending(page, id));
|
|
146
164
|
this.pending$.emit(this.state.pending);
|
|
165
|
+
this.events$.emit({ type: "remove", page, id });
|
|
147
166
|
},
|
|
148
167
|
clearPending: () => {
|
|
149
168
|
this.dispatch(clearPending());
|
|
150
169
|
this.pending$.emit(this.state.pending);
|
|
170
|
+
this.events$.emit({ type: "clear" });
|
|
151
171
|
},
|
|
152
172
|
commitAllPending: () => this.commitAllPending(),
|
|
153
173
|
commitPending: (page, id) => this.commitPendingOne(page, id),
|
|
154
174
|
endRedaction: () => this.endRedaction(),
|
|
155
175
|
startRedaction: () => this.startRedaction(),
|
|
156
|
-
onSelectionChange: this.selected$.on,
|
|
157
176
|
selectPending: (page, id) => this.selectPending(page, id),
|
|
158
177
|
deselectPending: () => this.deselectPending(),
|
|
159
|
-
|
|
178
|
+
onSelectedChange: this.selected$.on,
|
|
179
|
+
onRedactionEvent: this.events$.on,
|
|
180
|
+
onStateChange: this.state$.on,
|
|
181
|
+
onPendingChange: this.pending$.on
|
|
160
182
|
};
|
|
161
183
|
}
|
|
184
|
+
onRedactionSelectionChange(callback) {
|
|
185
|
+
return this.redactionSelection$.on(callback);
|
|
186
|
+
}
|
|
162
187
|
selectPending(page, id) {
|
|
163
188
|
var _a;
|
|
164
189
|
this.dispatch(selectPending(page, id));
|
|
@@ -171,27 +196,27 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
171
196
|
}
|
|
172
197
|
enableRedactSelection() {
|
|
173
198
|
var _a;
|
|
174
|
-
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(
|
|
199
|
+
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(RedactionMode.RedactSelection);
|
|
175
200
|
}
|
|
176
201
|
toggleRedactSelection() {
|
|
177
202
|
var _a, _b, _c;
|
|
178
|
-
if (((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) ===
|
|
203
|
+
if (((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === RedactionMode.RedactSelection)
|
|
179
204
|
(_b = this.interactionManagerCapability) == null ? void 0 : _b.activateDefaultMode();
|
|
180
|
-
else (_c = this.interactionManagerCapability) == null ? void 0 : _c.activate(
|
|
205
|
+
else (_c = this.interactionManagerCapability) == null ? void 0 : _c.activate(RedactionMode.RedactSelection);
|
|
181
206
|
}
|
|
182
207
|
enableMarqueeRedact() {
|
|
183
208
|
var _a;
|
|
184
|
-
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(
|
|
209
|
+
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(RedactionMode.MarqueeRedact);
|
|
185
210
|
}
|
|
186
211
|
toggleMarqueeRedact() {
|
|
187
212
|
var _a, _b, _c;
|
|
188
|
-
if (((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) ===
|
|
213
|
+
if (((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === RedactionMode.MarqueeRedact)
|
|
189
214
|
(_b = this.interactionManagerCapability) == null ? void 0 : _b.activateDefaultMode();
|
|
190
|
-
else (_c = this.interactionManagerCapability) == null ? void 0 : _c.activate(
|
|
215
|
+
else (_c = this.interactionManagerCapability) == null ? void 0 : _c.activate(RedactionMode.MarqueeRedact);
|
|
191
216
|
}
|
|
192
217
|
startRedaction() {
|
|
193
218
|
var _a;
|
|
194
|
-
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(
|
|
219
|
+
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate(RedactionMode.RedactSelection);
|
|
195
220
|
}
|
|
196
221
|
endRedaction() {
|
|
197
222
|
var _a;
|
|
@@ -252,7 +277,7 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
252
277
|
}
|
|
253
278
|
});
|
|
254
279
|
const off2 = this.interactionManagerCapability.registerHandlers({
|
|
255
|
-
modeId:
|
|
280
|
+
modeId: RedactionMode.MarqueeRedact,
|
|
256
281
|
handlers,
|
|
257
282
|
pageIndex: opts.pageIndex
|
|
258
283
|
});
|
|
@@ -278,7 +303,7 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
278
303
|
id,
|
|
279
304
|
kind: "text",
|
|
280
305
|
page: s.pageIndex,
|
|
281
|
-
|
|
306
|
+
rect: s.rect,
|
|
282
307
|
rects: s.segmentRects
|
|
283
308
|
}));
|
|
284
309
|
this.enableRedactSelection();
|
|
@@ -308,9 +333,13 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
308
333
|
this.dispatch(removePending(page, id));
|
|
309
334
|
this.pending$.emit(this.state.pending);
|
|
310
335
|
this.dispatchCoreAction(refreshPages([page]));
|
|
336
|
+
this.events$.emit({ type: "commit", success: true });
|
|
311
337
|
task.resolve(true);
|
|
312
338
|
},
|
|
313
|
-
() =>
|
|
339
|
+
(error) => {
|
|
340
|
+
this.events$.emit({ type: "commit", success: false, error: error.reason });
|
|
341
|
+
task.reject({ code: PdfErrorCode.Unknown, message: "Failed to commit redactions" });
|
|
342
|
+
}
|
|
314
343
|
);
|
|
315
344
|
return task;
|
|
316
345
|
}
|
|
@@ -346,20 +375,27 @@ const _RedactionPlugin = class _RedactionPlugin extends BasePlugin {
|
|
|
346
375
|
this.dispatch(clearPending());
|
|
347
376
|
this.dispatchCoreAction(refreshPages(pagesToRefresh));
|
|
348
377
|
this.pending$.emit(this.state.pending);
|
|
378
|
+
this.events$.emit({ type: "commit", success: true });
|
|
349
379
|
task.resolve(true);
|
|
350
380
|
},
|
|
351
|
-
() =>
|
|
381
|
+
(error) => {
|
|
382
|
+
this.events$.emit({ type: "commit", success: false, error: error.reason });
|
|
383
|
+
task.reject({ code: PdfErrorCode.Unknown, message: "Failed to commit redactions" });
|
|
384
|
+
}
|
|
352
385
|
);
|
|
353
386
|
return task;
|
|
354
387
|
}
|
|
355
388
|
onStoreUpdated(_, newState) {
|
|
356
389
|
this.pending$.emit(newState.pending);
|
|
357
390
|
this.selected$.emit(newState.selected);
|
|
391
|
+
this.state$.emit(newState);
|
|
358
392
|
}
|
|
359
393
|
async destroy() {
|
|
360
394
|
var _a, _b, _c;
|
|
361
395
|
this.redactionSelection$.clear();
|
|
362
396
|
this.pending$.clear();
|
|
397
|
+
this.state$.clear();
|
|
398
|
+
this.events$.clear();
|
|
363
399
|
(_a = this.unsubscribeSelectionChange) == null ? void 0 : _a.call(this);
|
|
364
400
|
(_b = this.unsubscribeEndSelection) == null ? void 0 : _b.call(this);
|
|
365
401
|
(_c = this.unsubscribeModeChange) == null ? void 0 : _c.call(this);
|
|
@@ -381,9 +417,14 @@ const manifest = {
|
|
|
381
417
|
drawBlackBoxes: true
|
|
382
418
|
}
|
|
383
419
|
};
|
|
420
|
+
const calculatePendingCount = (pending) => {
|
|
421
|
+
return Object.values(pending).reduce((total, items) => total + items.length, 0);
|
|
422
|
+
};
|
|
384
423
|
const initialState = {
|
|
385
424
|
isRedacting: false,
|
|
425
|
+
activeType: null,
|
|
386
426
|
pending: {},
|
|
427
|
+
pendingCount: 0,
|
|
387
428
|
selected: null
|
|
388
429
|
};
|
|
389
430
|
const redactionReducer = (state = initialState, action) => {
|
|
@@ -393,7 +434,7 @@ const redactionReducer = (state = initialState, action) => {
|
|
|
393
434
|
for (const item of action.payload) {
|
|
394
435
|
next[item.page] = (next[item.page] ?? []).concat(item);
|
|
395
436
|
}
|
|
396
|
-
return { ...state, pending: next };
|
|
437
|
+
return { ...state, pending: next, pendingCount: calculatePendingCount(next) };
|
|
397
438
|
}
|
|
398
439
|
case REMOVE_PENDING: {
|
|
399
440
|
const { page, id } = action.payload;
|
|
@@ -401,18 +442,32 @@ const redactionReducer = (state = initialState, action) => {
|
|
|
401
442
|
const filtered = list.filter((it) => it.id !== id);
|
|
402
443
|
const next = { ...state.pending, [page]: filtered };
|
|
403
444
|
const stillSelected = state.selected && !(state.selected.page === page && state.selected.id === id);
|
|
404
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
...state,
|
|
447
|
+
pending: next,
|
|
448
|
+
pendingCount: calculatePendingCount(next),
|
|
449
|
+
selected: stillSelected ? state.selected : null
|
|
450
|
+
};
|
|
405
451
|
}
|
|
406
452
|
case CLEAR_PENDING:
|
|
407
|
-
return { ...state, pending: {}, selected: null };
|
|
453
|
+
return { ...state, pending: {}, pendingCount: 0, selected: null };
|
|
408
454
|
case SELECT_PENDING:
|
|
409
455
|
return { ...state, selected: { page: action.payload.page, id: action.payload.id } };
|
|
410
456
|
case DESELECT_PENDING:
|
|
411
457
|
return { ...state, selected: null };
|
|
412
458
|
case START_REDACTION:
|
|
413
|
-
return { ...state, isRedacting: true };
|
|
459
|
+
return { ...state, isRedacting: true, activeType: action.payload };
|
|
414
460
|
case END_REDACTION:
|
|
415
|
-
return {
|
|
461
|
+
return {
|
|
462
|
+
...state,
|
|
463
|
+
pending: {},
|
|
464
|
+
pendingCount: 0,
|
|
465
|
+
selected: null,
|
|
466
|
+
isRedacting: false,
|
|
467
|
+
activeType: null
|
|
468
|
+
};
|
|
469
|
+
case SET_ACTIVE_TYPE:
|
|
470
|
+
return { ...state, activeType: action.payload };
|
|
416
471
|
default:
|
|
417
472
|
return state;
|
|
418
473
|
}
|
|
@@ -427,10 +482,12 @@ const RedactionPluginPackage = {
|
|
|
427
482
|
};
|
|
428
483
|
export {
|
|
429
484
|
REDACTION_PLUGIN_ID,
|
|
485
|
+
RedactionMode,
|
|
430
486
|
RedactionPlugin,
|
|
431
487
|
RedactionPluginPackage,
|
|
432
488
|
getPendingRedactionsCount,
|
|
433
489
|
hasPendingRedactions,
|
|
490
|
+
initialState,
|
|
434
491
|
manifest
|
|
435
492
|
};
|
|
436
493
|
//# sourceMappingURL=index.js.map
|