@milaboratories/pl-middle-layer 1.73.9 → 1.74.0

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,7 +1,7 @@
1
1
  //#region src/middle_layer/build_stamp.ts
2
2
  function injectedStamp() {
3
3
  try {
4
- return "ecc963c3efbd-dirty-1791228030682";
4
+ return "3ae16242be43-dirty-1791370259546";
5
5
  } catch {
6
6
  return;
7
7
  }
@@ -1,7 +1,7 @@
1
1
  //#region src/middle_layer/build_stamp.ts
2
2
  function injectedStamp() {
3
3
  try {
4
- return "ecc963c3efbd-dirty-1791228030652";
4
+ return "3ae16242be43-dirty-1791370259517";
5
5
  } catch {
6
6
  return;
7
7
  }
@@ -659,6 +659,49 @@ var MiddleLayer = class MiddleLayer {
659
659
  };
660
660
  }
661
661
  /**
662
+ * Stores a template brought in from outside — a template file the user picked — so it can be
663
+ * seen, applied and shared like one saved from a project.
664
+ *
665
+ * The document's description becomes the template's own, which stays editable; the stored
666
+ * document keeps only the blocks, without the label and description it was written with, so
667
+ * there is one name and one description to edit and nothing to drift.
668
+ *
669
+ * The template lands in `folder`, or at the top level, under `label` made free among the
670
+ * templates already there. A folder deleted meanwhile costs the template its placement, not its
671
+ * existence.
672
+ *
673
+ * @param document the parsed template to store
674
+ * @param options.label the name to store it under — usually the document's own label, which
675
+ * the caller weighs against whatever else it knows, such as the file's name; suffixed when a
676
+ * template there carries it
677
+ * @param options.folder where it lands; the top level when absent
678
+ */
679
+ async importTemplate(document, options) {
680
+ const { folder } = options;
681
+ const signedRid = await this.pl.withWriteTx("MLImportTemplate", async (tx) => {
682
+ const tree = await require_folders.openFoldersTx(tx, this.foldersRids);
683
+ const destination = folder !== void 0 && tree.view.folders.some((candidate) => candidate.id === folder) ? folder : void 0;
684
+ const name = (0, _milaboratories_pl_model_middle_layer.foldersUniqueName)(options.label.trim(), tree.namesTakenIn(destination, "template"));
685
+ const created = await require_template.createTemplate(tx, this.templateListResourceId, {
686
+ label: name,
687
+ description: document.description
688
+ }, {
689
+ schemaVersion: 1,
690
+ document: (0, _milaboratories_pl_model_common.withTemplateMeta)(document, {})
691
+ }).globalId;
692
+ if (destination !== void 0) tree.place([{
693
+ kind: "template",
694
+ id: (0, _milaboratories_pl_model_common.asTemplateId)((0, _milaboratories_pl_client.resourceIdToString)(created))
695
+ }], destination);
696
+ await tx.commit();
697
+ return created;
698
+ });
699
+ await Promise.all([this.templateListTree.refreshState(), ...folder === void 0 ? [] : [this.foldersTree.refreshState()]]);
700
+ const templateId = (0, _milaboratories_pl_model_common.asTemplateId)((0, _milaboratories_pl_client.resourceIdToString)(signedRid));
701
+ this.templateIdCache.set(templateId, signedRid);
702
+ return templateId;
703
+ }
704
+ /**
662
705
  * Changes a template's label. The stored document is immutable and stays untouched —
663
706
  * improving a template means saving a new one.
664
707
  *