@kwiz/common 1.0.82 → 1.0.84

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.
@@ -1,6 +1,7 @@
1
+ import { jsonClone } from "../../exports-index";
1
2
  import { PushNoDuplicate, firstOrNull, makeUniqueArray, toHash } from "../../helpers/collections.base";
2
3
  import { jsonStringify } from "../../helpers/json";
3
- import { NormalizeListName, SPBasePermissions, SchemaXmlToJson, extendFieldInfos } from "../../helpers/sharepoint";
4
+ import { NormalizeListName, SPBasePermissions, SchemaJsonToXml, SchemaXmlToJson, extendFieldInfos } from "../../helpers/sharepoint";
4
5
  import { normalizeGuid } from "../../helpers/strings";
5
6
  import { SafeIfElse, isBoolean, isNotEmptyArray, isNullOrEmptyArray, isNullOrEmptyString, isNullOrUndefined, isNumber, isPromise, isString, isValidGuid } from "../../helpers/typecheckers";
6
7
  import { makeServerRelativeUrl, normalizeUrl } from "../../helpers/url";
@@ -605,6 +606,64 @@ export async function UpdateField(siteUrlOrId: string, listIdOrTitle: string, fi
605
606
  }
606
607
  }
607
608
 
609
+ export default async function changeTextFieldMode(
610
+ siteUrlOrId: string,
611
+ listIdOrTitle: string,
612
+ textMode: "singleline" | "multiline" | "html",
613
+ currentField: IFieldInfoEX
614
+ ) {
615
+ const newSchema = jsonClone(currentField.SchemaJson);
616
+ const currentSchemaAttributes = newSchema.Attributes;
617
+
618
+ switch (textMode) {
619
+ case "singleline":
620
+ let shouldIntermediateUpdate = false;
621
+
622
+ if (currentSchemaAttributes.RichText === 'TRUE') {
623
+ currentSchemaAttributes.RichText = 'FALSE';
624
+ shouldIntermediateUpdate = true;
625
+ };
626
+ if (currentSchemaAttributes.RichTextMode === 'FullHTML') {
627
+ currentSchemaAttributes.RichTextMode = 'Compatible';
628
+ shouldIntermediateUpdate = true;
629
+ };
630
+
631
+ if (shouldIntermediateUpdate) {
632
+ const intermediateSchema = SchemaJsonToXml(newSchema);
633
+ const intermediateUpdatedField = await UpdateField(siteUrlOrId, listIdOrTitle, currentField.InternalName, {
634
+ SchemaXml: intermediateSchema
635
+ });
636
+ // Early exit if intermediate change failed.
637
+ if (isNullOrUndefined(intermediateUpdatedField))
638
+ return false;
639
+ };
640
+
641
+ // Actual type update.
642
+ currentSchemaAttributes.Type = 'Text';
643
+ delete currentSchemaAttributes.RichTextMode;
644
+ delete currentSchemaAttributes.RichText;
645
+ break;
646
+ case "multiline":
647
+ currentSchemaAttributes.Type = 'Note';
648
+ currentSchemaAttributes.RichText = 'FALSE';
649
+ currentSchemaAttributes.RichTextMode = 'Compatible';
650
+ break;
651
+ case "html":
652
+ currentSchemaAttributes.Type = 'Note';
653
+ currentSchemaAttributes.RichText = 'TRUE';
654
+ currentSchemaAttributes.RichTextMode = 'FullHTML';
655
+ break;
656
+ }
657
+
658
+ const updatedSchema = SchemaJsonToXml(newSchema);
659
+ const fieldUpdated = await UpdateField(siteUrlOrId, listIdOrTitle, currentField.InternalName, {
660
+ SchemaXml: updatedSchema
661
+ });
662
+
663
+ // If object is null or undefined then request has failed.
664
+ return !isNullOrUndefined(fieldUpdated);
665
+ }
666
+
608
667
  export async function DeleteField(siteUrl: string, listIdOrTitle: string, fieldInternalName: string, options?: { DeleteHiddenField?: boolean; }): Promise<boolean> {
609
668
  siteUrl = GetSiteUrl(siteUrl);
610
669