diff --git a/app/Http/Controllers/Publish/EditorController.php b/app/Http/Controllers/Publish/EditorController.php
index a993edf..10f9682 100644
--- a/app/Http/Controllers/Publish/EditorController.php
+++ b/app/Http/Controllers/Publish/EditorController.php
@@ -16,11 +16,13 @@ use App\Models\File;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
-use Illuminate\View\View;
+// use Illuminate\View\View;
+use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\DB;
// use App\Models\Coverage;
use Illuminate\Support\Facades\Validator;
use Carbon\Carbon;
+use \Exception;
class EditorController extends Controller
{
@@ -34,7 +36,7 @@ class EditorController extends Controller
*
* @return \Illuminate\Http\Response
*/
- public function index(): View
+ public function index(): \Illuminate\Contracts\View\View
{
$user = Auth::user();
$user_id = $user->id;
@@ -50,7 +52,7 @@ class EditorController extends Controller
})
->orderBy('server_date_modified', 'desc')
->get();
- return view('workflow.editor.index', compact('datasets'));
+ return View::make('workflow.editor.index', compact($datasets));
}
/**
@@ -59,11 +61,11 @@ class EditorController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function receive($id): View
+ public function receive($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
- return view('workflow.editor.receive', [
+ return View::make('workflow.editor.receive', [
'dataset' => $dataset,
]);
}
@@ -90,7 +92,7 @@ class EditorController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function edit($id): View
+ public function edit($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::findOrFail($id);
$dataset->load('licenses', 'titles', 'abstracts', 'files', 'coverage', 'subjects', 'references');
@@ -109,8 +111,13 @@ class EditorController extends Controller
->pluck('part1', 'part1');
//$options = License::all();
- $options = License::all('id', 'name_long');
- $checkeds = $dataset->licenses->pluck('id')->toArray();
+ // $options = License::all('id', 'name_long');
+ $licenses = License::select('id', 'name_long', 'link_licence')
+ ->orderBy('sort_order')
+ ->get();
+ //$checkeds = $dataset->licenses->pluck('id')->toArray();
+ $checkeds = $dataset->licenses->first()->id;
+
$keywordTypes = ['uncontrolled' => 'uncontrolled', 'swd' => 'swd'];
$referenceTypes = ["rdr-id", "arXiv", "bibcode", "DOI", "EAN13", "EISSN", "Handle", "IGSN", "ISBN", "ISSN", "ISTC", "LISSN", "LSID", "PMID", "PURL", "UPC", "URL", "URN"];
@@ -121,12 +128,12 @@ class EditorController extends Controller
$relationTypes = array_combine($relationTypes, $relationTypes);
- return view(
+ return View::make(
'workflow.editor.edit',
compact(
'dataset',
'projects',
- 'options',
+ 'licenses',
'checkeds',
'years',
'languages',
@@ -168,7 +175,7 @@ class EditorController extends Controller
],
];
$validator = Validator::make($request->all(), $rules);
- if ($validator->passes()) {
+ if (!$validator->fails()) {
$dataset = Dataset::findOrFail($id);
$data = $request->all();
$input = $request->except('abstracts', 'licenses', 'titles', 'coverage', '_method', '_token');
@@ -271,7 +278,7 @@ class EditorController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function approve($id): View
+ public function approve($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
@@ -279,7 +286,7 @@ class EditorController extends Controller
$q->where('name', 'reviewer');
})->pluck('login', 'id');
- return view('workflow.editor.approve', [
+ return View::make('workflow.editor.approve', [
'dataset' => $dataset,
'reviewers' => $reviewers,
]);
@@ -320,17 +327,17 @@ class EditorController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function reject($id): View
+ public function reject($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
- return view('workflow.editor.reject', [
+ return View::make('workflow.editor.reject', [
'dataset' => $dataset,
]);
}
public function rejectUpdate(Request $request, $id)
{
- $this->validate(request(), [
+ $this->validate($request, [
'reject_editor_note' => 'required|min:10|max:500',
'server_state' => 'required'
]);
@@ -353,7 +360,7 @@ class EditorController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function publish($id): View
+ public function publish($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::query()
->with([
@@ -363,7 +370,7 @@ class EditorController extends Controller
}
])->findOrFail($id);
- return view('workflow.editor.publish', [
+ return View::make('workflow.editor.publish', [
'dataset' => $dataset,
]);
}
diff --git a/app/Http/Controllers/Publish/SubmitController.php b/app/Http/Controllers/Publish/SubmitController.php
index a48b862..1bb60bb 100644
--- a/app/Http/Controllers/Publish/SubmitController.php
+++ b/app/Http/Controllers/Publish/SubmitController.php
@@ -9,7 +9,8 @@ use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
-use Illuminate\View\View;
+// use Illuminate\View\View;
+use Illuminate\Support\Facades\View;
// for edit actions:
use App\Models\Project;
use Illuminate\Support\Facades\DB;
@@ -20,6 +21,8 @@ use App\Models\Title;
use App\Models\Description;
use App\Models\File;
use App\Models\Subject;
+use App\Models\DatasetReference;
+use Exception;
class SubmitController extends Controller
{
@@ -28,7 +31,7 @@ class SubmitController extends Controller
//$this->middleware('auth');
}
- public function index(): View
+ public function index(): \Illuminate\Contracts\View\View
{
$user = Auth::user();
$user_id = $user->id;
@@ -42,7 +45,7 @@ class SubmitController extends Controller
->with('user:id,login')
->orderBy('server_date_modified', 'desc')
->get();
- return view('workflow.submitter.index', [
+ return View::make('workflow.submitter.index', [
'datasets' => $myDatasets,
]);
}
@@ -53,7 +56,7 @@ class SubmitController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function edit($id): View
+ public function edit($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::findOrFail($id);
$dataset->load('licenses', 'titles', 'abstracts', 'files', 'coverage', 'subjects', 'references');
@@ -70,26 +73,30 @@ class SubmitController extends Controller
$languages = DB::table('languages')
->where('active', true)
->pluck('part1', 'part1');
-
- //$options = License::all();
- $options = License::all('id', 'name_long');
- $checkeds = $dataset->licenses->pluck('id')->toArray();
+
+ // $options = License::all('id', 'name_long');
+ $licenses = License::select('id', 'name_long', 'link_licence')
+ ->orderBy('sort_order')
+ ->get();
+ // $checkeds = $dataset->licenses->pluck('id')->toArray();
+ $checkeds = $dataset->licenses->first()->id;
+
+
$keywordTypes = ['uncontrolled' => 'uncontrolled', 'swd' => 'swd'];
$referenceTypes = ["rdr-id", "arXiv", "bibcode", "DOI", "EAN13", "EISSN", "Handle", "IGSN", "ISBN", "ISSN", "ISTC", "LISSN", "LSID", "PMID", "PURL", "UPC", "URL", "URN"];
$referenceTypes = array_combine($referenceTypes, $referenceTypes);
- $relationTypes = ["IsCitedBy", "Cites", "IsSupplementTo", "IsSupplementedBy", "IsContinuedBy", "Continues", "HasMetadata", "IsMetadataFor","IsNewVersionOf", "IsPreviousVersionOf", "IsPartOf", "HasPart", "IsReferencedBy", "References"];
- // "IsDocumentedBy", "Documents", "IsCompiledBy", "Compiles", "IsVariantFormOf", "IsOriginalFormOf", "IsIdenticalTo", "IsReviewedBy", "Reviews", "IsDerivedFrom", "IsSourceOf"];
+ $relationTypes = ["IsCitedBy", "Cites", "IsSupplementTo", "IsSupplementedBy", "IsContinuedBy", "Continues", "HasMetadata", "IsMetadataFor","IsNewVersionOf", "IsPreviousVersionOf", "IsPartOf", "HasPart", "IsReferencedBy", "References", "IsDocumentedBy", "Documents", "IsCompiledBy", "Compiles", "IsVariantFormOf", "IsOriginalFormOf", "IsIdenticalTo", "IsReviewedBy", "Reviews", "IsDerivedFrom", "IsSourceOf"];
$relationTypes = array_combine($relationTypes, $relationTypes);
- return view(
+ return View::make(
'workflow.submitter.edit',
compact(
'dataset',
'projects',
- 'options',
+ 'licenses',
'checkeds',
'years',
'languages',
@@ -129,12 +136,18 @@ class SubmitController extends Controller
'nullable',
'regex:/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/'
],
+ 'keywords.*.value' => 'required|string',
+ 'keywords.*.type' => 'required|string',
+ 'files.*.label' => 'required|string',
];
- $validator = Validator::make($request->all(), $rules);
- if ($validator->passes()) {
+ $customMessages = [
+ 'keywords.*.type.required' => 'The types of all keywords are required.'
+ ];
+ $validator = Validator::make($request->all(), $rules, $customMessages);
+ if (!$validator->fails()) {
$dataset = Dataset::findOrFail($id);
$data = $request->all();
- $input = $request->except('abstracts', 'licenses', 'titles', 'coverage', '_method', '_token');
+ $input = $request->except('abstracts', 'licenses', 'titles', 'coverage', 'subjects', 'files', '_method', '_token');
$licenses = $request->input('licenses');
//$licenses = $input['licenses'];
@@ -147,7 +160,9 @@ class SubmitController extends Controller
$title = Title::findOrFail($key);
$title->value = $formTitle['value'];
$title->language = $formTitle['language'];
- $title->save();
+ if ($title->isDirty()) {
+ $title->save();
+ }
}
}
@@ -158,7 +173,9 @@ class SubmitController extends Controller
$abstract = Description::findOrFail($key);
$abstract->value = $formAbstract['value'];
$abstract->language = $formAbstract['language'];
- $abstract->save();
+ if ($abstract->isDirty()) {
+ $abstract->save();
+ }
}
}
@@ -171,18 +188,22 @@ class SubmitController extends Controller
$reference->label = $formReference['label'];
$reference->type = $formReference['type'];
$reference->relation = $formReference['relation'];
- $reference->save();
+ if ($reference->isDirty()) {
+ $reference->save();
+ }
}
}
//save the keywords:
- $keywords = $request->input('keywords');
+ $keywords = $request->input('subjects');
if (is_array($keywords) && count($keywords) > 0) {
foreach ($keywords as $key => $formKeyword) {
$subject = Subject::findOrFail($key);
$subject->value = $formKeyword['value'];
$subject->type = $formKeyword['type'];
- $subject->save();
+ if ($subject->isDirty()) {
+ $subject->save();
+ }
}
}
@@ -192,20 +213,28 @@ class SubmitController extends Controller
foreach ($files as $key => $formFile) {
$file = File::findOrFail($key);
$file->label = $formFile['label'];
- $file->save();
+ if ($file->isDirty()) {
+ $file->save();
+ }
}
}
// save coverage
- if (isset($data['coverage'])) {
+ if (isset($data['coverage']) && !$this->containsOnlyNull($data['coverage'])) {
$formCoverage = $request->input('coverage');
$coverage = $dataset->coverage()->updateOrCreate(
['dataset_id' => $dataset->id],
$formCoverage
);
+ } elseif (isset($data['coverage']) && $this->containsOnlyNull($data['coverage'])
+ && !is_null($dataset->coverage)) {
+ $dataset->coverage()->delete();
}
- if (!$dataset->isDirty(dataset::UPDATED_AT)) {
+ $dataset->fill($input);
+ // $dataset->creating_corporation = "Peter";
+
+ if (!$dataset->isDirty()) {
$time = new \Illuminate\Support\Carbon();
$dataset->setUpdatedAt($time);
}
@@ -222,12 +251,19 @@ class SubmitController extends Controller
// 'success' => false,
// 'errors' => $validator->errors()->all(),
// ], 422);
- return back()
+ return back()->withInput()
->withErrors($validator->errors()->all());
}
throw new GeneralException(trans('exceptions.backend.dataset.update_error'));
}
+ private function containsOnlyNull($input)
+ {
+ return empty(array_filter($input, function ($a) {
+ return $a !== null;
+ }));
+ }
+
/**
* Display the specified resource.
@@ -235,7 +271,7 @@ class SubmitController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function release($id): View
+ public function release($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
@@ -244,7 +280,7 @@ class SubmitController extends Controller
})->pluck('login', 'id');
//$editors = Role::where('name', 'editor')->first()->users()->get();
- return view('workflow.submitter.release', [
+ return View::make('workflow.submitter.release', [
'dataset' => $dataset,
'editors' => $editors,
]);
@@ -288,11 +324,11 @@ class SubmitController extends Controller
* @param int $id
* @return \Illuminate\View\View
*/
- public function delete($id): View
+ public function delete($id): \Illuminate\Contracts\View\View
{
$dataset = Dataset::with('user:id,login')->findOrFail($id);
- return view('workflow.submitter.delete', [
+ return View::make('workflow.submitter.delete', [
'dataset' => $dataset
]);
}
diff --git a/public/backend/ckeditor.js b/public/backend/ckeditor.js
index 52630b8..836d0ca 100644
--- a/public/backend/ckeditor.js
+++ b/public/backend/ckeditor.js
@@ -1 +1 @@
-!function(t){var e={};function n(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(i,o,function(e){return t[e]}.bind(null,o));return i},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=170)}({170:function(t,e,n){t.exports=n(171)},171:function(t,e,n){"use strict";n.r(e);for(var i=n(83),o=n.n(i),r=document.querySelectorAll(".ckeditor"),s=0;s
").replace(/^\s/," ").replace(/\s$/," ").replace(/\s\s/g," ")).indexOf("
")>-1&&(t=`
${t}
`),t}(i.getData("text/plain"))),o=this._htmlDataProcessor.toView(o),this.fire("inputTransformation",{content:o,dataTransfer:i}),n.scrollToTheSelection()},{priority:"low"}),this.listenTo(this,"inputTransformation",(t,e)=>{if(!e.content.isEmpty){const t=this.editor.data,n=this.editor.model,i=t.toModel(e.content,"$clipboardHolder");if(0==i.childCount)return;n.insertContent(i)}},{priority:"low"}),this.listenTo(i,"copy",o,{priority:"low"}),this.listenTo(i,"cut",(e,n)=>{t.isReadOnly?n.preventDefault():o(e,n)},{priority:"low"}),this.listenTo(i,"clipboardOutput",(n,i)=>{i.content.isEmpty||(i.dataTransfer.setData("text/html",this._htmlDataProcessor.toData(i.content)),i.dataTransfer.setData("text/plain",function t(e){let n="";if(e.is("text")||e.is("textProxy"))n=e.data;else if(e.is("img")&&e.hasAttribute("alt"))n=e.getAttribute("alt");else{let i=null;for(const o of e.getChildren()){const e=t(o);i&&(i.is("containerElement")||o.is("containerElement"))&&(za.includes(i.name)||za.includes(o.name)?n+="\n":n+="\n\n"),n+=e,i=o}}return n}(i.content))),"cut"==i.method&&t.model.deleteContent(e.selection)},{priority:"low"})}}class Fa{constructor(t){this.editor=t,this.set("value",void 0),this.set("isEnabled",!1),this._disableStack=new Set,this.decorate("execute"),this.listenTo(this.editor.model.document,"change",()=>{this.refresh()}),this.on("execute",t=>{this.isEnabled||t.stop()},{priority:"high"}),this.listenTo(t,"change:isReadOnly",(t,e,n)=>{n?this.forceDisabled("readOnlyMode"):this.clearForceDisabled("readOnlyMode")})}refresh(){this.isEnabled=!0}forceDisabled(t){this._disableStack.add(t),1==this._disableStack.size&&(this.on("set:isEnabled",Ua,{priority:"highest"}),this.isEnabled=!1)}clearForceDisabled(t){this._disableStack.delete(t),0==this._disableStack.size&&(this.off("set:isEnabled",Ua),this.refresh())}execute(){}destroy(){this.stopListening()}}function Ua(t){t.return=!1,t.stop()}function*Ha(t,e){for(const n of e)n&&t.getAttributeProperties(n[0]).copyOnEnter&&(yield n)}Ie(Fa,sn);class qa extends Fa{execute(){const t=this.editor.model,e=t.document;t.change(n=>{!function(t,e,n,i){const o=n.isCollapsed,r=n.getFirstRange(),s=r.start.parent,a=r.end.parent;if(i.isLimit(s)||i.isLimit(a))o||s!=a||t.deleteContent(n);else if(o){const t=Ha(e.model.schema,n.getAttributes());Wa(e,r.start),e.setSelectionAttribute(t)}else{const i=!(r.start.isAtStart&&r.end.isAtEnd),o=s==a;t.deleteContent(n,{leaveUnmerged:i}),i&&(o?Wa(e,n.focus):e.setSelection(a,0))}}(this.editor.model,n,e.selection,t.schema),this.fire("afterExecute",{writer:n})})}}function Wa(t,e){t.split(e),t.setSelection(e.parent.nextSibling,0)}class Ya extends Mi{constructor(t){super(t);const e=this.document;e.on("keydown",(t,n)=>{if(this.isEnabled&&n.keyCode==Dn.enter){let i;e.once("enter",t=>i=t,{priority:"highest"}),e.fire("enter",new Gi(e,n.domEvent,{isSoft:n.shiftKey})),i&&i.stop.called&&t.stop()}})}observe(){}}class $a extends La{static get pluginName(){return"Enter"}init(){const t=this.editor,e=t.editing.view,n=e.document;e.addObserver(Ya),t.commands.add("enter",new qa(t)),this.listenTo(n,"enter",(n,i)=>{i.preventDefault(),i.isSoft||(t.execute("enter"),e.scrollToTheSelection())},{priority:"low"})}}class Ga extends Fa{execute(){const t=this.editor.model,e=t.document;t.change(n=>{!function(t,e,n){const i=n.isCollapsed,o=n.getFirstRange(),r=o.start.parent,s=o.end.parent,a=r==s;if(i){const i=Ha(t.schema,n.getAttributes());Qa(e,o.end),e.removeSelectionAttribute(n.getAttributeKeys()),e.setSelectionAttribute(i)}else{const i=!(o.start.isAtStart&&o.end.isAtEnd);t.deleteContent(n,{leaveUnmerged:i}),a?Qa(e,n.focus):i&&e.setSelection(s,0)}}(t,n,e.selection),this.fire("afterExecute",{writer:n})})}refresh(){const t=this.editor.model,e=t.document;this.isEnabled=function(t,e){if(e.rangeCount>1)return!1;const n=e.anchor;if(!n||!t.checkChild(n,"softBreak"))return!1;const i=e.getFirstRange(),o=i.start.parent,r=i.end.parent;return!Ka(o,t)&&!Ka(r,t)||o===r}(t.schema,e.selection)}}function Qa(t,e){const n=t.createElement("softBreak");t.insert(n,e),t.setSelection(n,"after")}function Ka(t,e){return!t.is("rootElement")&&(e.isLimit(t)||Ka(t.parent,e))}class Ja extends La{static get pluginName(){return"ShiftEnter"}init(){const t=this.editor,e=t.model.schema,n=t.conversion,i=t.editing.view,o=i.document;e.register("softBreak",{allowWhere:"$text",isInline:!0}),n.for("upcast").elementToElement({model:"softBreak",view:"br"}),n.for("downcast").elementToElement({model:"softBreak",view:(t,e)=>e.createEmptyElement("br")}),i.addObserver(Ya),t.commands.add("shiftEnter",new Ga(t)),this.listenTo(o,"enter",(e,n)=>{n.preventDefault(),n.isSoft&&(t.execute("shiftEnter"),i.scrollToTheSelection())},{priority:"low"})}}class Za{constructor(t,e=20){this.model=t,this.size=0,this.limit=e,this.isLocked=!1,this._changeCallback=(t,e)=>{"transparent"!=e.type&&e!==this._batch&&this._reset(!0)},this._selectionChangeCallback=()=>{this._reset()},this.model.document.on("change",this._changeCallback),this.model.document.selection.on("change:range",this._selectionChangeCallback),this.model.document.selection.on("change:attribute",this._selectionChangeCallback)}get batch(){return this._batch||(this._batch=this.model.createBatch()),this._batch}input(t){this.size+=t,this.size>=this.limit&&this._reset(!0)}lock(){this.isLocked=!0}unlock(){this.isLocked=!1}destroy(){this.model.document.off("change",this._changeCallback),this.model.document.selection.off("change:range",this._selectionChangeCallback),this.model.document.selection.off("change:attribute",this._selectionChangeCallback)}_reset(t){this.isLocked&&!t||(this._batch=null,this.size=0)}}class Xa extends Fa{constructor(t,e){super(t),this._buffer=new Za(t.model,e),this._batches=new WeakSet}get buffer(){return this._buffer}destroy(){super.destroy(),this._buffer.destroy()}execute(t={}){const e=this.editor.model,n=e.document,i=t.text||"",o=i.length,r=t.range||n.selection.getFirstRange(),s=t.resultRange;e.enqueueChange(this._buffer.batch,t=>{const a=r.isCollapsed;this._buffer.lock(),e.deleteContent(e.createSelection(r)),i&&e.insertContent(t.createText(i,n.selection.getAttributes()),r.start),s?t.setSelection(s):a&&t.setSelection(r.start.getShiftedBy(o)),this._buffer.unlock(),this._buffer.input(o),this._batches.add(this._buffer.batch)})}}const tc=[Ln("arrowUp"),Ln("arrowRight"),Ln("arrowDown"),Ln("arrowLeft"),9,16,17,18,19,20,27,33,34,35,36,45,91,93,144,145,173,174,175,176,177,178,179,255];for(let t=112;t<=135;t++)tc.push(t);function ec(t){if(t.newChildren.length-t.oldChildren.length!=1)return;const e=function(t,e){const n=[];let i,o=0;return t.forEach(t=>{"equal"==t?(r(),o++):"insert"==t?(s("insert")?i.values.push(e[o]):(r(),i={type:"insert",index:o,values:[e[o]]}),o++):s("delete")?i.howMany++:(r(),i={type:"delete",index:o,howMany:1})}),r(),n;function r(){i&&(n.push(i),i=null)}function s(t){return i&&i.type==t}}(ui(t.oldChildren,t.newChildren,nc),t.newChildren);if(e.length>1)return;const n=e[0];return n.values[0]&&n.values[0].is("text")?n:void 0}function nc(t,e){return t&&t.is("text")&&e&&e.is("text")?t.data===e.data:t===e}class ic{constructor(t){this.editor=t,this.editing=this.editor.editing}handle(t,e){if(function(t){if(0==t.length)return!1;for(const e of t)if("children"===e.type&&!ec(e))return!0;return!1}(t))this._handleContainerChildrenMutations(t,e);else for(const n of t)this._handleTextMutation(n,e),this._handleTextNodeInsertion(n)}_handleContainerChildrenMutations(t,e){const n=function(t){const e=t.map(t=>t.node).reduce((t,e)=>t.getCommonAncestor(e,{includeSelf:!0}));if(e)return e.getAncestors({includeSelf:!0,parentFirst:!0}).find(t=>t.is("containerElement")||t.is("rootElement"))}(t);if(!n)return;const i=this.editor.editing.view.domConverter.mapViewToDom(n),o=new yi,r=this.editor.data.toModel(o.domToView(i)).getChild(0),s=this.editor.editing.mapper.toModelElement(n);if(!s)return;const a=Array.from(r.getChildren()),c=Array.from(s.getChildren()),l=a[a.length-1],d=c[c.length-1];l&&l.is("softBreak")&&d&&!d.is("softBreak")&&a.pop();const h=this.editor.model.schema;if(!oc(a,h)||!oc(c,h))return;const u=a.map(t=>t.is("text")?t.data:"@").join("").replace(/\u00A0/g," "),f=c.map(t=>t.is("text")?t.data:"@").join("").replace(/\u00A0/g," ");if(f===u)return;const g=ui(f,u),{firstChangeAt:m,insertions:p,deletions:b}=rc(g);let w=null;e&&(w=this.editing.mapper.toModelRange(e.getFirstRange()));const k=u.substr(m,p),_=this.editor.model.createRange(this.editor.model.createPositionAt(s,m),this.editor.model.createPositionAt(s,m+b));this.editor.execute("input",{text:k,range:_,resultRange:w})}_handleTextMutation(t,e){if("text"!=t.type)return;const n=t.newText.replace(/\u00A0/g," "),i=t.oldText.replace(/\u00A0/g," ");if(i===n)return;const o=ui(i,n),{firstChangeAt:r,insertions:s,deletions:a}=rc(o);let c=null;e&&(c=this.editing.mapper.toModelRange(e.getFirstRange()));const l=this.editing.view.createPositionAt(t.node,r),d=this.editing.mapper.toModelPosition(l),h=this.editor.model.createRange(d,d.getShiftedBy(a)),u=n.substr(r,s);this.editor.execute("input",{text:u,range:h,resultRange:c})}_handleTextNodeInsertion(t){if("children"!=t.type)return;const e=ec(t),n=this.editing.view.createPositionAt(t.node,e.index),i=this.editing.mapper.toModelPosition(n),o=e.values[0].data;this.editor.execute("input",{text:o.replace(/\u00A0/g," "),range:this.editor.model.createRange(i)})}}function oc(t,e){return t.every(t=>e.isInline(t))}function rc(t){let e=null,n=null;for(let i=0;i