charon-conversation-editor 0.0.24 → 0.0.30

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/assets/index.css CHANGED
@@ -1083,6 +1083,7 @@ svg.react-flow__connectionline {
1083
1083
  line-height: 1.5;
1084
1084
  }
1085
1085
 
1086
+ .ext-ce-schema-validation-container .ext-ce-schema-name,
1086
1087
  .ext-ce-schema-validation-container .ext-ce-error-message code {
1087
1088
  background-color: #edf2f7;
1088
1089
  padding: 2px 6px;
@@ -1093,7 +1094,7 @@ svg.react-flow__connectionline {
1093
1094
  }
1094
1095
 
1095
1096
 
1096
- .ext-ce-schema-validation-container .ext-ce-copy-button {
1097
+ .ext-ce-schema-validation-container .ext-ce-migrate-button {
1097
1098
  background-color: var(--ext-panel-background-color);
1098
1099
  border: 1px solid var(--app-color-gray);
1099
1100
  outline: none;
@@ -1107,6 +1108,6 @@ svg.react-flow__connectionline {
1107
1108
  text-align: left;
1108
1109
  }
1109
1110
 
1110
- .ext-ce-schema-validation-container .ext-ce-copy-button:hover {
1111
+ .ext-ce-schema-validation-container .ext-ce-migrate-button:hover {
1111
1112
  background-color: var(--app-light-gray-background);
1112
1113
  }
package/index.js CHANGED
@@ -7157,7 +7157,7 @@ function requireReactDomClient_production() {
7157
7157
  function commitHostUpdate(finishedWork, newProps, oldProps) {
7158
7158
  try {
7159
7159
  var domElement = finishedWork.stateNode;
7160
- updateProperties(domElement, finishedWork.type, oldProps, newProps);
7160
+ updateProperties2(domElement, finishedWork.type, oldProps, newProps);
7161
7161
  domElement[internalPropsKey] = newProps;
7162
7162
  } catch (error) {
7163
7163
  captureCommitPhaseError(finishedWork, finishedWork.return, error);
@@ -10741,7 +10741,7 @@ function requireReactDomClient_production() {
10741
10741
  for (defaultValue in props)
10742
10742
  props.hasOwnProperty(defaultValue) && (hasSrc = props[defaultValue], null != hasSrc && setProp(domElement, tag, defaultValue, hasSrc, props, null));
10743
10743
  }
10744
- function updateProperties(domElement, tag, lastProps, nextProps) {
10744
+ function updateProperties2(domElement, tag, lastProps, nextProps) {
10745
10745
  switch (tag) {
10746
10746
  case "div":
10747
10747
  case "span":
@@ -21179,11 +21179,25 @@ function ResizeControl({ nodeId, position, variant = ResizeControlVariant.Handle
21179
21179
  }, children: children2 });
21180
21180
  }
21181
21181
  reactExports.memo(ResizeControl);
21182
+ function isValueControl(value) {
21183
+ return !!value && typeof value === "object" && // probe few properties and functions
21184
+ typeof value.type === "string" && typeof value.changeStatus === "string" && typeof value.setValue === "function" && typeof value.makeWriteable === "function";
21185
+ }
21186
+ function isRootDocumentControl(value) {
21187
+ return !!value && value.type === "document" && "schema" in value && (!value.schemaProperty || Object.is(value.schemaProperty, value.schema.getIdProperty()));
21188
+ }
21189
+ function getRootDocumentControl(value) {
21190
+ const rootOrNull = isValueControl(value) ? value.root : null;
21191
+ if (!isRootDocumentControl(rootOrNull)) {
21192
+ throw new Error("Unable to find root node for the specified control.");
21193
+ }
21194
+ return rootOrNull;
21195
+ }
21182
21196
  function isDocumentCollectionControl(value) {
21183
21197
  return value && value.type === "document-collection";
21184
21198
  }
21185
21199
  function isDocumentControl(value) {
21186
- return value && value.type === "document";
21200
+ return !!value && value.type === "document";
21187
21201
  }
21188
21202
  var DataType = /* @__PURE__ */ ((DataType2) => {
21189
21203
  DataType2[DataType2["Text"] = 0] = "Text";
@@ -21534,36 +21548,36 @@ class ConversationState {
21534
21548
  };
21535
21549
  }
21536
21550
  }
21537
- setDialogNextNode(dialogNodeId, targetDialogNodeId, comparisonTargetDialogNodeId, opts) {
21551
+ setDialogNextNode(dialogNodeId, targetDialogNodeId, changeTargetFromId, opts) {
21538
21552
  var _a;
21539
21553
  const dialogNodeControl = this.findDialogNode(dialogNodeId);
21540
21554
  if (!dialogNodeControl) {
21541
21555
  return;
21542
21556
  }
21543
21557
  const nextNodeControl = dialogNodeControl.controls.NextNode;
21544
- if (comparisonTargetDialogNodeId !== void 0 && ((_a = nextNodeControl.value) == null ? void 0 : _a.Id) != comparisonTargetDialogNodeId) {
21558
+ if (changeTargetFromId !== void 0 && ((_a = nextNodeControl.value) == null ? void 0 : _a.Id) != changeTargetFromId) {
21545
21559
  return;
21546
21560
  }
21547
21561
  const nextNodeReference = this.getNextNodeReference(targetDialogNodeId);
21548
21562
  nextNodeControl.setValue(nextNodeReference, opts);
21549
21563
  }
21550
- setDialogResponseNextNode(dialogNodeId, dialogResponseId, targetDialogNodeId, comparisonTargetDialogNodeId, opts) {
21564
+ setDialogResponseNextNode(dialogNodeId, dialogResponseId, targetDialogNodeId, changeTargetFromId, opts) {
21551
21565
  var _a;
21552
21566
  const dialogResponseControl = this.findDialogResponse(dialogNodeId, dialogResponseId);
21553
21567
  if (!dialogResponseControl) {
21554
21568
  return;
21555
21569
  }
21556
21570
  const nextNodeControl = dialogResponseControl.controls.NextNode;
21557
- if (comparisonTargetDialogNodeId !== void 0 && ((_a = nextNodeControl.value) == null ? void 0 : _a.Id) != comparisonTargetDialogNodeId) {
21571
+ if (changeTargetFromId !== void 0 && ((_a = nextNodeControl.value) == null ? void 0 : _a.Id) != changeTargetFromId) {
21558
21572
  return;
21559
21573
  }
21560
21574
  const nextNodeReference = this.getNextNodeReference(targetDialogNodeId);
21561
21575
  nextNodeControl.setValue(nextNodeReference, opts);
21562
21576
  }
21563
- setRootNode(targetDialogNodeId, comparisonTargetDialogNodeId, opts) {
21577
+ setRootNode(targetDialogNodeId, changeTargetFromId, opts) {
21564
21578
  var _a;
21565
21579
  const rootNodeControl = this.conversationTreeControl.controls.RootNode;
21566
- if (comparisonTargetDialogNodeId !== void 0 && ((_a = rootNodeControl.value) == null ? void 0 : _a.Id) != comparisonTargetDialogNodeId) {
21580
+ if (changeTargetFromId !== void 0 && ((_a = rootNodeControl.value) == null ? void 0 : _a.Id) != changeTargetFromId) {
21567
21581
  return;
21568
21582
  }
21569
21583
  const nextNodeReference = this.getNextNodeReference(targetDialogNodeId);
@@ -22973,6 +22987,30 @@ function of() {
22973
22987
  var scheduler2 = popScheduler(args);
22974
22988
  return from(args, scheduler2);
22975
22989
  }
22990
+ var EmptyError = createErrorClass(function(_super) {
22991
+ return function EmptyErrorImpl() {
22992
+ _super(this);
22993
+ this.name = "EmptyError";
22994
+ this.message = "no elements in sequence";
22995
+ };
22996
+ });
22997
+ function firstValueFrom(source, config2) {
22998
+ return new Promise(function(resolve, reject) {
22999
+ var subscriber = new SafeSubscriber({
23000
+ next: function(value) {
23001
+ resolve(value);
23002
+ subscriber.unsubscribe();
23003
+ },
23004
+ error: reject,
23005
+ complete: function() {
23006
+ {
23007
+ reject(new EmptyError());
23008
+ }
23009
+ }
23010
+ });
23011
+ source.subscribe(subscriber);
23012
+ });
23013
+ }
22976
23014
  class UndoRedoState {
22977
23015
  /**
22978
23016
  * Creates a new UndoRedoState instance for managing ValueControl history
@@ -23352,6 +23390,18 @@ class DevSchema {
23352
23390
  getHashCode() {
23353
23391
  return 0;
23354
23392
  }
23393
+ toDocument() {
23394
+ return {
23395
+ Id: this.id,
23396
+ Name: this.name,
23397
+ DisplayName: this.displayName,
23398
+ Type: this.type,
23399
+ Description: this.description,
23400
+ IdGenerator: this.idGenerator,
23401
+ Specification: this.specification,
23402
+ Properties: this.properties.map((property) => property.toDocument())
23403
+ };
23404
+ }
23355
23405
  toString() {
23356
23406
  return this.name;
23357
23407
  }
@@ -23884,6 +23934,22 @@ class DevSchemaProperty {
23884
23934
  getHashCode() {
23885
23935
  return 0;
23886
23936
  }
23937
+ toDocument() {
23938
+ return {
23939
+ Id: this.id,
23940
+ SharedProperty: this.sharedProperty ? { Id: this.sharedProperty.id } : null,
23941
+ Name: this.name,
23942
+ DisplayName: this.displayName,
23943
+ Description: this.description,
23944
+ DataType: this.dataType,
23945
+ DefaultValue: this.defaultValue,
23946
+ Uniqueness: this.uniqueness,
23947
+ Requirement: this.requirement,
23948
+ ReferenceType: this.referenceType ? { Id: this.referenceType.id, DisplayName: this.referenceType.displayName } : null,
23949
+ Size: this.size,
23950
+ Specification: this.specification
23951
+ };
23952
+ }
23887
23953
  toString() {
23888
23954
  return this.name;
23889
23955
  }
@@ -34439,11 +34505,35 @@ function validateProperty(schema, modelPath, propertyName, expectedTypes, errors
34439
34505
  });
34440
34506
  }
34441
34507
  }
34442
- const ConversationSchema = {
34508
+ var ImportMode = /* @__PURE__ */ ((ImportMode2) => {
34509
+ ImportMode2[ImportMode2["createAndUpdate"] = 0] = "createAndUpdate";
34510
+ ImportMode2[ImportMode2["create"] = 1] = "create";
34511
+ ImportMode2[ImportMode2["update"] = 2] = "update";
34512
+ ImportMode2[ImportMode2["safeUpdate"] = 3] = "safeUpdate";
34513
+ ImportMode2[ImportMode2["replace"] = 4] = "replace";
34514
+ ImportMode2[ImportMode2["delete"] = 5] = "delete";
34515
+ return ImportMode2;
34516
+ })(ImportMode || {});
34517
+ var ValidationOption = /* @__PURE__ */ ((ValidationOption2) => {
34518
+ ValidationOption2[ValidationOption2["repair"] = 0] = "repair";
34519
+ ValidationOption2[ValidationOption2["checkTranslations"] = 1] = "checkTranslations";
34520
+ ValidationOption2[ValidationOption2["deduplicateIds"] = 2] = "deduplicateIds";
34521
+ ValidationOption2[ValidationOption2["repairRequiredWithDefaults"] = 3] = "repairRequiredWithDefaults";
34522
+ ValidationOption2[ValidationOption2["resolveConflictingUnions"] = 4] = "resolveConflictingUnions";
34523
+ ValidationOption2[ValidationOption2["eraseInvalidValues"] = 5] = "eraseInvalidValues";
34524
+ ValidationOption2[ValidationOption2["checkRequirements"] = 6] = "checkRequirements";
34525
+ ValidationOption2[ValidationOption2["checkFormat"] = 7] = "checkFormat";
34526
+ ValidationOption2[ValidationOption2["checkUniqueness"] = 8] = "checkUniqueness";
34527
+ ValidationOption2[ValidationOption2["checkReferences"] = 9] = "checkReferences";
34528
+ ValidationOption2[ValidationOption2["checkSpecification"] = 10] = "checkSpecification";
34529
+ ValidationOption2[ValidationOption2["checkConstraints"] = 11] = "checkConstraints";
34530
+ return ValidationOption2;
34531
+ })(ValidationOption || {});
34532
+ const conversationSchema = {
34443
34533
  "Collections": {
34444
34534
  "Schema": [
34445
34535
  {
34446
- "Id": "68efe4c7c1e4b04cc8f8d232",
34536
+ "Id": "_ID_DialogResponse_8d232",
34447
34537
  "Name": "DialogResponse",
34448
34538
  "DisplayName": "Dialog Response",
34449
34539
  "Type": 1,
@@ -34452,7 +34542,7 @@ const ConversationSchema = {
34452
34542
  "Specification": "displayTextTemplate=%7BText%7D",
34453
34543
  "Properties": [
34454
34544
  {
34455
- "Id": "68efe4c7c1e4b04cc8f8d22f",
34545
+ "Id": "_ID_68efe4c7c1e4b04cc8f8d22f",
34456
34546
  "SharedProperty": null,
34457
34547
  "Name": "Id",
34458
34548
  "DisplayName": "Id",
@@ -34466,7 +34556,7 @@ const ConversationSchema = {
34466
34556
  "Specification": "display=hidden"
34467
34557
  },
34468
34558
  {
34469
- "Id": "68efe4c7c1e4b04cc8f8d230",
34559
+ "Id": "_ID_68efe4c7c1e4b04cc8f8d230",
34470
34560
  "SharedProperty": null,
34471
34561
  "Name": "Text",
34472
34562
  "DisplayName": "Text",
@@ -34480,7 +34570,7 @@ const ConversationSchema = {
34480
34570
  "Specification": "editor=localized-text-multiline"
34481
34571
  },
34482
34572
  {
34483
- "Id": "68efe4edc1e4b04cc8f8d240",
34573
+ "Id": "_ID_68efe4edc1e4b04cc8f8d240",
34484
34574
  "SharedProperty": null,
34485
34575
  "Name": "NextNode",
34486
34576
  "DisplayName": "Next Node",
@@ -34490,14 +34580,14 @@ const ConversationSchema = {
34490
34580
  "Uniqueness": 0,
34491
34581
  "Requirement": 0,
34492
34582
  "ReferenceType": {
34493
- "Id": "68efe4cbc1e4b04cc8f8d239",
34583
+ "Id": "_ID_DialogNode_8d239",
34494
34584
  "DisplayName": "Dialog Node"
34495
34585
  },
34496
34586
  "Size": 0,
34497
34587
  "Specification": ""
34498
34588
  },
34499
34589
  {
34500
- "Id": "68efe4c7c1e4b04cc8f8d231",
34590
+ "Id": "_ID_68efe4c7c1e4b04cc8f8d231",
34501
34591
  "SharedProperty": null,
34502
34592
  "Name": "Specification",
34503
34593
  "DisplayName": "Specification",
@@ -34513,7 +34603,7 @@ const ConversationSchema = {
34513
34603
  ]
34514
34604
  },
34515
34605
  {
34516
- "Id": "68efe4cbc1e4b04cc8f8d239",
34606
+ "Id": "_ID_DialogNode_8d239",
34517
34607
  "Name": "DialogNode",
34518
34608
  "DisplayName": "Dialog Node",
34519
34609
  "Type": 1,
@@ -34522,7 +34612,7 @@ const ConversationSchema = {
34522
34612
  "Specification": "displayTextTemplate=%7BText%7D",
34523
34613
  "Properties": [
34524
34614
  {
34525
- "Id": "68efe4cbc1e4b04cc8f8d234",
34615
+ "Id": "_ID_68efe4cbc1e4b04cc8f8d234",
34526
34616
  "SharedProperty": null,
34527
34617
  "Name": "Id",
34528
34618
  "DisplayName": "Id",
@@ -34536,7 +34626,7 @@ const ConversationSchema = {
34536
34626
  "Specification": "display=hidden"
34537
34627
  },
34538
34628
  {
34539
- "Id": "68efe4cbc1e4b04cc8f8d235",
34629
+ "Id": "_ID_68efe4cbc1e4b04cc8f8d235",
34540
34630
  "SharedProperty": null,
34541
34631
  "Name": "Text",
34542
34632
  "DisplayName": "Text",
@@ -34550,7 +34640,7 @@ const ConversationSchema = {
34550
34640
  "Specification": "editor=localized-text-multiline"
34551
34641
  },
34552
34642
  {
34553
- "Id": "68efe4cbc1e4b04cc8f8d236",
34643
+ "Id": "_ID_68efe4cbc1e4b04cc8f8d236",
34554
34644
  "SharedProperty": null,
34555
34645
  "Name": "NextNode",
34556
34646
  "DisplayName": "Next Node",
@@ -34560,14 +34650,14 @@ const ConversationSchema = {
34560
34650
  "Uniqueness": 0,
34561
34651
  "Requirement": 0,
34562
34652
  "ReferenceType": {
34563
- "Id": "68efe4cbc1e4b04cc8f8d239",
34653
+ "Id": "_ID_DialogNode_8d239",
34564
34654
  "DisplayName": "Dialog Node"
34565
34655
  },
34566
34656
  "Size": 0,
34567
34657
  "Specification": ""
34568
34658
  },
34569
34659
  {
34570
- "Id": "68efe4cbc1e4b04cc8f8d237",
34660
+ "Id": "_ID_68efe4cbc1e4b04cc8f8d237",
34571
34661
  "SharedProperty": null,
34572
34662
  "Name": "Responses",
34573
34663
  "DisplayName": "Responses",
@@ -34577,14 +34667,14 @@ const ConversationSchema = {
34577
34667
  "Uniqueness": 0,
34578
34668
  "Requirement": 2,
34579
34669
  "ReferenceType": {
34580
- "Id": "68efe4c7c1e4b04cc8f8d232",
34670
+ "Id": "_ID_DialogResponse_8d232",
34581
34671
  "DisplayName": "Dialog Response"
34582
34672
  },
34583
34673
  "Size": 0,
34584
34674
  "Specification": ""
34585
34675
  },
34586
34676
  {
34587
- "Id": "68efe4cbc1e4b04cc8f8d238",
34677
+ "Id": "_ID_68efe4cbc1e4b04cc8f8d238",
34588
34678
  "SharedProperty": null,
34589
34679
  "Name": "Specification",
34590
34680
  "DisplayName": "Specification",
@@ -34600,7 +34690,7 @@ const ConversationSchema = {
34600
34690
  ]
34601
34691
  },
34602
34692
  {
34603
- "Id": "68efe4d3c1e4b04cc8f8d23e",
34693
+ "Id": "_ID_ConversationTree_8d23e",
34604
34694
  "Name": "ConversationTree",
34605
34695
  "DisplayName": "Conversation",
34606
34696
  "Type": 0,
@@ -34609,7 +34699,7 @@ const ConversationSchema = {
34609
34699
  "Specification": "editor=ext-conversation-editor&displayTextTemplate=%7BId%7D&icon=emoji%2Fspeech_balloon",
34610
34700
  "Properties": [
34611
34701
  {
34612
- "Id": "68efe4d3c1e4b04cc8f8d23b",
34702
+ "Id": "_ID_68efe4d3c1e4b04cc8f8d23b",
34613
34703
  "SharedProperty": null,
34614
34704
  "Name": "Id",
34615
34705
  "DisplayName": "Id",
@@ -34623,7 +34713,7 @@ const ConversationSchema = {
34623
34713
  "Specification": ""
34624
34714
  },
34625
34715
  {
34626
- "Id": "68efe527c1e4b04cc8f8d243",
34716
+ "Id": "_ID_68efe527c1e4b04cc8f8d243",
34627
34717
  "SharedProperty": null,
34628
34718
  "Name": "RootNode",
34629
34719
  "DisplayName": "Root Node",
@@ -34633,14 +34723,14 @@ const ConversationSchema = {
34633
34723
  "Uniqueness": 0,
34634
34724
  "Requirement": 2,
34635
34725
  "ReferenceType": {
34636
- "Id": "68efe4cbc1e4b04cc8f8d239",
34726
+ "Id": "_ID_DialogNode_8d239",
34637
34727
  "DisplayName": "Dialog Node"
34638
34728
  },
34639
34729
  "Size": 0,
34640
34730
  "Specification": ""
34641
34731
  },
34642
34732
  {
34643
- "Id": "68efe4d3c1e4b04cc8f8d23d",
34733
+ "Id": "_ID_68efe4d3c1e4b04cc8f8d23d",
34644
34734
  "SharedProperty": null,
34645
34735
  "Name": "Nodes",
34646
34736
  "DisplayName": "Nodes",
@@ -34650,14 +34740,14 @@ const ConversationSchema = {
34650
34740
  "Uniqueness": 0,
34651
34741
  "Requirement": 2,
34652
34742
  "ReferenceType": {
34653
- "Id": "68efe4cbc1e4b04cc8f8d239",
34743
+ "Id": "_ID_DialogNode_8d239",
34654
34744
  "DisplayName": "Dialog Node"
34655
34745
  },
34656
34746
  "Size": 0,
34657
34747
  "Specification": ""
34658
34748
  },
34659
34749
  {
34660
- "Id": "68efe4d3c1e4b04cc8f8d23c",
34750
+ "Id": "_ID_68efe4d3c1e4b04cc8f8d23c",
34661
34751
  "SharedProperty": null,
34662
34752
  "Name": "Specification",
34663
34753
  "DisplayName": "Specification",
@@ -34675,19 +34765,135 @@ const ConversationSchema = {
34675
34765
  ]
34676
34766
  }
34677
34767
  };
34768
+ const ConversationSchema = conversationSchema;
34769
+ async function migrateSchema(schema, dataSource) {
34770
+ var _a, _b, _c;
34771
+ const nodesProperty = schema.findSchemaProperty("Nodes");
34772
+ const dialogNodeSchema = nodesProperty && nodesProperty.dataType === DataType.DocumentCollection ? nodesProperty.getReferencedSchema() : null;
34773
+ const responsesProperty = dialogNodeSchema == null ? void 0 : dialogNodeSchema.findSchemaProperty("Responses");
34774
+ const responseSchema = responsesProperty && responsesProperty.dataType === DataType.DocumentCollection ? responsesProperty.getReferencedSchema() : null;
34775
+ const schemaQuery = from(dataSource.query([schema.id, dialogNodeSchema == null ? void 0 : dialogNodeSchema.id, responseSchema == null ? void 0 : responseSchema.id].filter((id2) => Boolean(id2)).map((uniqueSchemaPropertyValue) => ({ schemaNameOrId: "Schema", uniqueSchemaPropertyNameOrId: "Id", uniqueSchemaPropertyValue }))));
34776
+ const existingSchemaDocuments = await firstValueFrom(schemaQuery);
34777
+ const expectedConversationTreeSchemaDocument = ConversationSchema.Collections.Schema.find((schemaDocument) => schemaDocument.Name === "ConversationTree");
34778
+ const expectedDialogNodeSchemaDocument = ConversationSchema.Collections.Schema.find((schemaDocument) => schemaDocument.Name === "DialogNode");
34779
+ const expectedDialogResponseSchemaDocument = ConversationSchema.Collections.Schema.find((schemaDocument) => schemaDocument.Name === "DialogResponse");
34780
+ const conversationTreeSchemaDocument = deepClone(((_a = existingSchemaDocuments.find((result) => {
34781
+ var _a2;
34782
+ return String((_a2 = result.document) == null ? void 0 : _a2.Id) === schema.id;
34783
+ })) == null ? void 0 : _a.document) ?? expectedConversationTreeSchemaDocument);
34784
+ const dialogNodeSchemaDocument = deepClone(((_b = existingSchemaDocuments.find((result) => {
34785
+ var _a2;
34786
+ return String((_a2 = result.document) == null ? void 0 : _a2.Id) === (dialogNodeSchema == null ? void 0 : dialogNodeSchema.id);
34787
+ })) == null ? void 0 : _b.document) ?? expectedDialogNodeSchemaDocument);
34788
+ const dialogResponseSchemaDocument = deepClone(((_c = existingSchemaDocuments.find((result) => {
34789
+ var _a2;
34790
+ return String((_a2 = result.document) == null ? void 0 : _a2.Id) === (responseSchema == null ? void 0 : responseSchema.id);
34791
+ })) == null ? void 0 : _c.document) ?? expectedDialogResponseSchemaDocument);
34792
+ updateProperties(conversationTreeSchemaDocument, expectedConversationTreeSchemaDocument);
34793
+ updateProperties(dialogNodeSchemaDocument, expectedDialogNodeSchemaDocument);
34794
+ updateProperties(dialogResponseSchemaDocument, expectedDialogResponseSchemaDocument);
34795
+ updateRefrenceType(conversationTreeSchemaDocument, "RootNode", dialogNodeSchemaDocument);
34796
+ updateRefrenceType(conversationTreeSchemaDocument, "Nodes", dialogNodeSchemaDocument);
34797
+ updateRefrenceType(dialogNodeSchemaDocument, "NextNode", dialogNodeSchemaDocument);
34798
+ updateRefrenceType(dialogNodeSchemaDocument, "Responses", dialogResponseSchemaDocument);
34799
+ updateRefrenceType(dialogResponseSchemaDocument, "NextNode", dialogNodeSchemaDocument);
34800
+ const importDocuments = {
34801
+ Collections: {
34802
+ Schema: [
34803
+ conversationTreeSchemaDocument,
34804
+ dialogNodeSchemaDocument,
34805
+ dialogResponseSchemaDocument
34806
+ ]
34807
+ }
34808
+ };
34809
+ const importQuery = from(
34810
+ dataSource.import(
34811
+ // documents
34812
+ importDocuments,
34813
+ // type of documents to import = Schema
34814
+ ["Schema"],
34815
+ // import mode
34816
+ ImportMode.createAndUpdate,
34817
+ // languages = all
34818
+ void 0,
34819
+ // validation options = default for creation/updating
34820
+ [
34821
+ ValidationOption.repair,
34822
+ ValidationOption.repairRequiredWithDefaults,
34823
+ ValidationOption.checkRequirements,
34824
+ ValidationOption.checkFormat,
34825
+ ValidationOption.checkReferences,
34826
+ ValidationOption.checkUniqueness,
34827
+ ValidationOption.checkSpecification,
34828
+ ValidationOption.checkConstraints
34829
+ ],
34830
+ // dry run = no
34831
+ void 0
34832
+ )
34833
+ );
34834
+ await firstValueFrom(importQuery);
34835
+ }
34836
+ function deepClone(value) {
34837
+ return JSON.parse(JSON.stringify(value));
34838
+ }
34839
+ function updateProperties(schemaDocument, expectedSchemaDocument) {
34840
+ const properties = schemaDocument.Properties ?? [];
34841
+ const expectedProperties = expectedSchemaDocument.Properties ?? [];
34842
+ for (const expectedProperty of expectedProperties) {
34843
+ const existingProperty = properties.find((propertyDocument) => String(propertyDocument.Name) === String(expectedProperty.Name));
34844
+ if (existingProperty && existingProperty.Name === "Id") {
34845
+ continue;
34846
+ } else if (existingProperty) {
34847
+ updateProperty(existingProperty, expectedProperty);
34848
+ } else {
34849
+ properties.push(deepClone(expectedProperty));
34850
+ }
34851
+ }
34852
+ schemaDocument.Properties = properties;
34853
+ }
34854
+ function updateProperty(schemaPropertyDocument, expectedSchemaPropertyDocument) {
34855
+ for (const propertyName in expectedSchemaPropertyDocument) {
34856
+ if (!Object.prototype.hasOwnProperty.call(expectedSchemaPropertyDocument, propertyName)) continue;
34857
+ const propertyValue = expectedSchemaPropertyDocument[propertyName];
34858
+ schemaPropertyDocument[propertyName] = propertyValue;
34859
+ }
34860
+ }
34861
+ function updateRefrenceType(schemaDocument, propertyName, referencedSchema) {
34862
+ var _a;
34863
+ const properties = schemaDocument.Properties ?? [];
34864
+ const property = properties.find((propertyDocument) => String(propertyDocument.Name) === propertyName);
34865
+ if (!property) {
34866
+ return;
34867
+ }
34868
+ if (![DataType.Document, DataType.DocumentCollection, DataType.Reference, DataType.ReferenceCollection].includes(property.DataType)) {
34869
+ return;
34870
+ }
34871
+ const schemaReference = { Id: String(referencedSchema.Id), DisplayName: String(referencedSchema.DisplayName) };
34872
+ if (((_a = property.ReferenceType) == null ? void 0 : _a.Id) === schemaReference.Id) {
34873
+ return;
34874
+ }
34875
+ property.ReferenceType = schemaReference;
34876
+ }
34678
34877
  function SchemaValidationResult({ documentControl }) {
34679
34878
  const errors = validateSchema(documentControl.schema);
34680
34879
  const validationResult = { isValid: !errors.length, errors };
34681
- const copySchemaHandler = reactExports.useCallback(() => {
34682
- const textToCopy = JSON.stringify(ConversationSchema);
34683
- navigator.clipboard.writeText(textToCopy).catch((error) => {
34684
- console.error("Failed to copy text to clipboard: ", error);
34685
- });
34686
- }, []);
34880
+ const [migrationError, setMigrationError] = reactExports.useState("");
34881
+ const services = getRootDocumentControl(documentControl).services;
34882
+ const dataService = services.dataService;
34883
+ const [migrateIsPending, setMigrateIsPending] = reactExports.useState(false);
34884
+ const migrateSchemaHandler = reactExports.useCallback(() => {
34885
+ setMigrateIsPending(true);
34886
+ setMigrationError("");
34887
+ migrateSchema(documentControl.schema, dataService).catch((error) => setMigrationError(String(error))).catch((error) => console.error(error)).then(() => window.location.reload()).finally(() => setMigrateIsPending(false));
34888
+ }, [dataService, documentControl]);
34687
34889
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ext-ce-schema-validation-container", children: [
34688
34890
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ext-ce-validation-header", children: [
34689
34891
  /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { children: "Schema Validation" }),
34690
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "This editor requires a specific document schema to function properly. You can correct the errors listed below or import the entire schema directly." }),
34892
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { children: [
34893
+ "This editor requires a specific document schema to function properly. You can correct the errors listed below or",
34894
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "migrate" }),
34895
+ " the schema to the required format."
34896
+ ] }),
34691
34897
  validationResult.isValid ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ext-ce-validation-status valid", children: [
34692
34898
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "ext-ce-status-icon", children: "✓" }),
34693
34899
  "Schema is valid"
@@ -34704,35 +34910,20 @@ function SchemaValidationResult({ documentControl }) {
34704
34910
  validationResult.errors.map((error, index2) => /* @__PURE__ */ jsxRuntimeExports.jsx(ValidationErrorItem, { error }, index2))
34705
34911
  ] }),
34706
34912
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "ext-ce-schema-import", children: [
34707
- /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Importing Schema" }),
34708
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "You can create a proper data schema for the dialog editor by importing it:" }),
34709
- /* @__PURE__ */ jsxRuntimeExports.jsxs("ol", { children: [
34710
- /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
34711
- "Go to ",
34712
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Dashboard" }),
34713
- " → ",
34714
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Import Documents" })
34715
- ] }),
34716
- /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
34717
- "Option: Create and Update ",
34718
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Next" })
34719
- ] }),
34720
- /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
34721
- "Option: Clipboard → ",
34722
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Next" })
34723
- ] }),
34724
- /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
34725
- "Click the ",
34726
- /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "ext-ce-copy-button", onClick: copySchemaHandler, children: "Copy Schema" }),
34727
- " and paste into the input field → ",
34728
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Next" })
34729
- ] }),
34730
- /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { children: [
34731
- "Checkbox All → ",
34732
- /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Import" })
34733
- ] })
34734
- ] })
34735
- ] })
34913
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Schema Migration" }),
34914
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { children: [
34915
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Migrate" }),
34916
+ " the ",
34917
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "ext-ce-schema-name", children: documentControl.schema.displayName }),
34918
+ " schema to the required structure. This action will attempt to fix structural issues while preserving existing data."
34919
+ ] }),
34920
+ /* @__PURE__ */ jsxRuntimeExports.jsx("button", { className: "ext-ce-migrate-button", onClick: migrateSchemaHandler, disabled: migrateIsPending, children: "Migrate Schema" })
34921
+ ] }),
34922
+ migrationError && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "ext-ce-validation-error-item", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "ext-ce-error-message", children: [
34923
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: "Schema Migration Error:" }),
34924
+ " ",
34925
+ migrationError
34926
+ ] }) })
34736
34927
  ] }) });
34737
34928
  }
34738
34929
  function ValidationErrorItem({ error }) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/gamedevware/charon-extensions/refs/heads/main/package.json.schema.json",
3
3
  "name": "charon-conversation-editor",
4
- "version": "0.0.24",
4
+ "version": "0.0.30",
5
5
  "description": "",
6
6
  "keywords": [
7
7
  "charon",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@xyflow/react": "^12.8.6",
41
- "charon-extensions": "2.314.388",
41
+ "charon-extensions": "2.325.398",
42
42
  "dagre": "^0.8.5",
43
43
  "react": "^19.2.0",
44
44
  "react-dom": "^19.2.0",
@@ -61,4 +61,4 @@
61
61
  "typescript-eslint": "^8.24.1",
62
62
  "vite": "^6.2.0"
63
63
  }
64
- }
64
+ }