@univerjs/sheets-drawing 1.0.0-alpha.1 → 1.0.0-insiders.20260701-0ef51b0

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/lib/cjs/index.js CHANGED
@@ -3,6 +3,7 @@ let _univerjs_sheets = require("@univerjs/sheets");
3
3
  let _univerjs_core = require("@univerjs/core");
4
4
  let _univerjs_drawing = require("@univerjs/drawing");
5
5
  let _univerjs_engine_render = require("@univerjs/engine-render");
6
+ let _univerjs_embed = require("@univerjs/embed");
6
7
 
7
8
  //#region src/basics/transform-position.ts
8
9
  function drawingPositionToTransform(position, sheetSkeletonParam) {
@@ -581,10 +582,639 @@ SheetsDrawingLoadController = __decorate([
581
582
  __decorateParam(5, _univerjs_core.IResourceManagerService)
582
583
  ], SheetsDrawingLoadController);
583
584
 
585
+ //#endregion
586
+ //#region src/embed-floating-anchor.ts
587
+ const EMBED_SHEETS_FLOATING_COMPONENT_KEY = "UniverEmbedSheetsFloatingObject";
588
+ const DEFAULT_LEFT = 80;
589
+ const DEFAULT_TOP = 80;
590
+ const DEFAULT_WIDTH = 560;
591
+ const DEFAULT_HEIGHT = 360;
592
+ const MIN_FLOATING_SIZE = 1;
593
+ function createEmbedSheetsFloatingObjectData(params) {
594
+ var _params$runtimeMountM;
595
+ return {
596
+ version: 1,
597
+ embedId: params.embedId,
598
+ hostType: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
599
+ childType: params.childType,
600
+ hostUnitId: params.hostUnitId,
601
+ hostAnchorId: params.hostAnchorId,
602
+ runtimeMountMode: (_params$runtimeMountM = params.runtimeMountMode) !== null && _params$runtimeMountM !== void 0 ? _params$runtimeMountM : "stage2",
603
+ resizeBehavior: params.resizeBehavior,
604
+ aspectRatio: params.aspectRatio,
605
+ disablePopup: true
606
+ };
607
+ }
608
+ function createEmbedSheetsFloatingDrawing(params) {
609
+ var _params$left, _params$top, _params$sheetTransfor, _params$componentKey, _params$allowTransfor;
610
+ const left = (_params$left = params.left) !== null && _params$left !== void 0 ? _params$left : DEFAULT_LEFT;
611
+ const top = (_params$top = params.top) !== null && _params$top !== void 0 ? _params$top : DEFAULT_TOP;
612
+ const { width, height } = resolveEmbedSheetsFloatingObjectSize({
613
+ width: params.width,
614
+ height: params.height,
615
+ resizeBehavior: params.resizeBehavior,
616
+ aspectRatio: params.aspectRatio
617
+ });
618
+ const sheetTransform = (_params$sheetTransfor = params.sheetTransform) !== null && _params$sheetTransfor !== void 0 ? _params$sheetTransfor : createDefaultSheetTransform(left, top, width, height);
619
+ return {
620
+ unitId: params.hostUnitId,
621
+ subUnitId: params.hostSubUnitId,
622
+ drawingId: params.hostAnchorId,
623
+ drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_BLOCK,
624
+ componentKey: (_params$componentKey = params.componentKey) !== null && _params$componentKey !== void 0 ? _params$componentKey : EMBED_SHEETS_FLOATING_COMPONENT_KEY,
625
+ sheetTransform,
626
+ axisAlignSheetTransform: sheetTransform,
627
+ transform: {
628
+ left,
629
+ top,
630
+ width,
631
+ height
632
+ },
633
+ data: createEmbedSheetsFloatingObjectData(params),
634
+ allowTransform: (_params$allowTransfor = params.allowTransform) !== null && _params$allowTransfor !== void 0 ? _params$allowTransfor : true
635
+ };
636
+ }
637
+ function resolveEmbedSheetsFloatingObjectSize(params) {
638
+ const width = isValidPositiveNumber(params.width) ? params.width : DEFAULT_WIDTH;
639
+ const height = isValidPositiveNumber(params.height) ? params.height : DEFAULT_HEIGHT;
640
+ const aspectRatio = isValidPositiveNumber(params.aspectRatio) ? params.aspectRatio : void 0;
641
+ if (params.resizeBehavior !== "aspect-ratio" || !aspectRatio) return {
642
+ width,
643
+ height
644
+ };
645
+ if (isValidPositiveNumber(params.width)) return {
646
+ width,
647
+ height: Math.max(MIN_FLOATING_SIZE, width / aspectRatio)
648
+ };
649
+ if (isValidPositiveNumber(params.height)) return {
650
+ width: Math.max(MIN_FLOATING_SIZE, height * aspectRatio),
651
+ height
652
+ };
653
+ return {
654
+ width,
655
+ height: Math.max(MIN_FLOATING_SIZE, width / aspectRatio)
656
+ };
657
+ }
658
+ function createEmbedSheetsFloatingDrawingFromDescriptor(descriptor, hostSubUnitId, hostContext) {
659
+ var _getString;
660
+ return createEmbedSheetsFloatingDrawing({
661
+ embedId: descriptor.embedId,
662
+ childType: descriptor.childType,
663
+ hostUnitId: descriptor.hostUnitId,
664
+ hostSubUnitId,
665
+ hostAnchorId: descriptor.hostAnchorId,
666
+ componentKey: (_getString = getString$1(hostContext, "componentKey")) !== null && _getString !== void 0 ? _getString : void 0,
667
+ left: getNumber$1(hostContext, "left"),
668
+ top: getNumber$1(hostContext, "top"),
669
+ width: getNumber$1(hostContext, "width"),
670
+ height: getNumber$1(hostContext, "height"),
671
+ sheetTransform: getSheetTransform$1(hostContext),
672
+ allowTransform: getBoolean$1(hostContext, "allowTransform"),
673
+ resizeBehavior: getResizeBehavior(hostContext),
674
+ aspectRatio: getNumber$1(hostContext, "aspectRatio"),
675
+ runtimeMountMode: getRuntimeMountMode(hostContext)
676
+ });
677
+ }
678
+ function getEmbedSheetsFloatingObjectData(drawing) {
679
+ if (!isEmbedSheetsFloatingObjectData(drawing.data)) return;
680
+ return drawing.data;
681
+ }
682
+ function isEmbedSheetsFloatingDrawing(drawing) {
683
+ return drawing.componentKey === "UniverEmbedSheetsFloatingObject" && getEmbedSheetsFloatingObjectData(drawing) != null;
684
+ }
685
+ function createDefaultSheetTransform(left, top, width, height) {
686
+ return {
687
+ from: {
688
+ column: 0,
689
+ columnOffset: left,
690
+ row: 0,
691
+ rowOffset: top
692
+ },
693
+ to: {
694
+ column: 0,
695
+ columnOffset: left + width,
696
+ row: 0,
697
+ rowOffset: top + height
698
+ }
699
+ };
700
+ }
701
+ function getNumber$1(hostContext, key) {
702
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "number" ? hostContext[key] : void 0;
703
+ }
704
+ function getString$1(hostContext, key) {
705
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "string" ? hostContext[key] : void 0;
706
+ }
707
+ function getBoolean$1(hostContext, key) {
708
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "boolean" ? hostContext[key] : void 0;
709
+ }
710
+ function isValidPositiveNumber(value) {
711
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
712
+ }
713
+ function getResizeBehavior(hostContext) {
714
+ const value = hostContext === null || hostContext === void 0 ? void 0 : hostContext.resizeBehavior;
715
+ return value === "free" || value === "aspect-ratio" || value === "height-auto" || value === "disabled" ? value : void 0;
716
+ }
717
+ function getRuntimeMountMode(hostContext) {
718
+ const value = hostContext === null || hostContext === void 0 ? void 0 : hostContext.runtimeMountMode;
719
+ return value === "always" || value === "stage2" ? value : void 0;
720
+ }
721
+ function getSheetTransform$1(hostContext) {
722
+ const value = hostContext === null || hostContext === void 0 ? void 0 : hostContext.sheetTransform;
723
+ if (!value || typeof value !== "object") return;
724
+ const candidate = value;
725
+ if (!candidate.from || !candidate.to) return;
726
+ return candidate;
727
+ }
728
+ function isEmbedSheetsFloatingObjectData(value) {
729
+ if (!value || typeof value !== "object") return false;
730
+ const candidate = value;
731
+ return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
732
+ }
733
+
734
+ //#endregion
735
+ //#region src/embed-host-adapter.ts
736
+ function registerSheetsDrawingEmbedHostAdapters(injector) {
737
+ (0, _univerjs_embed.registerEmbedHostAdapterContributions)(injector, [createSheetsFloatingObjectHostAdapterContribution(injector.has(_univerjs_embed.EmbedHostAnchorModelService) ? injector.get(_univerjs_embed.EmbedHostAnchorModelService) : void 0, () => injector.has(ISheetDrawingService) ? injector.get(ISheetDrawingService) : void 0, () => injector.has(_univerjs_drawing.IDrawingManagerService) ? injector.get(_univerjs_drawing.IDrawingManagerService) : void 0, () => injector.has(_univerjs_sheets.SheetSkeletonService) ? injector.get(_univerjs_sheets.SheetSkeletonService) : void 0)]);
738
+ }
739
+ function createSheetsFloatingObjectHostAdapterContribution(anchorModelService, sheetDrawingService, drawingManagerService, sheetSkeletonService) {
740
+ return {
741
+ hostType: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
742
+ entry: "sheets-floating-object",
743
+ createAnchorPlan: (context) => requireAnchorPlan(createSheetsFloatingObjectAnchorPlan(context, getSheetDrawingService(sheetDrawingService), getSheetSkeletonService(sheetSkeletonService)), "EMBED_SHEETS_FLOATING_ANCHOR_UNAVAILABLE"),
744
+ restoreAnchor: (context) => requireAnchorRecord$1(restoreSheetsFloatingObjectAnchor(context, getSheetDrawingService(sheetDrawingService), getDrawingManagerService(drawingManagerService), getSheetSkeletonService(sheetSkeletonService)), "EMBED_SHEETS_FLOATING_ANCHOR_UNAVAILABLE"),
745
+ removeAnchorPlan: (context) => {
746
+ const previous = anchorModelService === null || anchorModelService === void 0 ? void 0 : anchorModelService.getAnchor(context.hostUnitId, context.hostAnchorId);
747
+ const record = previous !== null && previous !== void 0 ? previous : createSheetsFloatingObjectRecord(context);
748
+ const plan = createSheetsFloatingObjectRemoveAnchorPlan(context, record, getSheetDrawingService(sheetDrawingService));
749
+ return plan !== null && plan !== void 0 ? plan : createRecordOnlyRemovePlan(context, record);
750
+ }
751
+ };
752
+ }
753
+ function createSheetsFloatingObjectAnchorPlan(context, sheetDrawingService, sheetSkeletonService) {
754
+ const hostSubUnitId = getHostSubUnitId(context.hostContext);
755
+ if (!sheetDrawingService || !hostSubUnitId) return;
756
+ const record = createSheetsFloatingObjectRecord(context);
757
+ const drawing = createSheetsFloatingObjectDrawing(context, record, hostSubUnitId, sheetSkeletonService);
758
+ if (!drawing) return;
759
+ const jsonOp = sheetDrawingService.getBatchAddOp([drawing]);
760
+ const drawingSearch = {
761
+ unitId: record.hostUnitId,
762
+ subUnitId: hostSubUnitId,
763
+ drawingId: record.hostAnchorId
764
+ };
765
+ return {
766
+ hostAnchorId: record.hostAnchorId,
767
+ redoMutations: [toSetDrawingMutation(jsonOp, 0, "redo"), {
768
+ id: _univerjs_embed.SET_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
769
+ params: { record }
770
+ }],
771
+ undoMutations: [{
772
+ id: _univerjs_embed.REMOVE_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
773
+ params: {
774
+ hostUnitId: record.hostUnitId,
775
+ hostAnchorId: record.hostAnchorId
776
+ }
777
+ }, toSetDrawingMutation({
778
+ ...jsonOp,
779
+ objects: [drawingSearch]
780
+ }, 1, "undo")]
781
+ };
782
+ }
783
+ function createSheetsFloatingObjectRemoveAnchorPlan(context, record, sheetDrawingService) {
784
+ const hostSubUnitId = getHostSubUnitId(record.hostContext);
785
+ if (!sheetDrawingService || !hostSubUnitId) return;
786
+ const jsonOp = sheetDrawingService.getBatchRemoveOp([{
787
+ unitId: context.hostUnitId,
788
+ subUnitId: hostSubUnitId,
789
+ drawingId: context.hostAnchorId
790
+ }]);
791
+ return {
792
+ redoMutations: [{
793
+ id: _univerjs_embed.REMOVE_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
794
+ params: {
795
+ hostUnitId: context.hostUnitId,
796
+ hostAnchorId: context.hostAnchorId
797
+ }
798
+ }, toSetDrawingMutation(jsonOp, 1, "redo")],
799
+ undoMutations: [toSetDrawingMutation(jsonOp, 0, "undo"), {
800
+ id: _univerjs_embed.SET_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
801
+ params: { record: {
802
+ ...record,
803
+ lifecycle: "active"
804
+ } }
805
+ }]
806
+ };
807
+ }
808
+ function createSheetsFloatingObjectRecord(context) {
809
+ return createRecord({
810
+ ...context,
811
+ hostContext: normalizeSheetsFloatingObjectHostContext(context)
812
+ }, "sheets-floating-object", "sheets-floating");
813
+ }
814
+ function restoreSheetsFloatingObjectAnchor(context, sheetDrawingService, drawingManagerService, sheetSkeletonService) {
815
+ var _sheetDrawingService$;
816
+ const hostSubUnitId = getHostSubUnitId(context.hostContext);
817
+ if (!sheetDrawingService || !drawingManagerService || !hostSubUnitId) return;
818
+ const record = createSheetsFloatingObjectRecord({
819
+ ...context,
820
+ requestedAnchorId: context.hostAnchorId
821
+ });
822
+ const drawing = createSheetsFloatingObjectDrawing(context, record, hostSubUnitId, sheetSkeletonService);
823
+ if (!drawing) return;
824
+ const drawingSearch = {
825
+ unitId: record.hostUnitId,
826
+ subUnitId: hostSubUnitId,
827
+ drawingId: record.hostAnchorId
828
+ };
829
+ if (!((_sheetDrawingService$ = sheetDrawingService.getDrawingData(record.hostUnitId, hostSubUnitId)) === null || _sheetDrawingService$ === void 0 ? void 0 : _sheetDrawingService$[record.hostAnchorId])) {
830
+ const jsonOp = sheetDrawingService.getBatchAddOp([drawing]);
831
+ drawingManagerService.applyJson1(record.hostUnitId, hostSubUnitId, jsonOp.redo);
832
+ sheetDrawingService.applyJson1(record.hostUnitId, hostSubUnitId, jsonOp.redo);
833
+ drawingManagerService.addNotification([drawingSearch]);
834
+ sheetDrawingService.addNotification([drawingSearch]);
835
+ }
836
+ return record;
837
+ }
838
+ function createSheetsFloatingObjectDrawing(context, record, hostSubUnitId, sheetSkeletonService) {
839
+ var _context$descriptor, _getString, _context$descriptor2, _getNumber, _context$descriptor3, _transformToAxisAlign;
840
+ const drawing = createEmbedSheetsFloatingDrawing({
841
+ embedId: record.embedId,
842
+ childType: (_context$descriptor = context.descriptor) === null || _context$descriptor === void 0 ? void 0 : _context$descriptor.childType,
843
+ hostUnitId: record.hostUnitId,
844
+ hostSubUnitId,
845
+ hostAnchorId: record.hostAnchorId,
846
+ componentKey: (_getString = getString(record.hostContext, "componentKey")) !== null && _getString !== void 0 ? _getString : void 0,
847
+ left: getNumber(record.hostContext, "left"),
848
+ top: getNumber(record.hostContext, "top"),
849
+ width: getNumber(record.hostContext, "width"),
850
+ height: getNumber(record.hostContext, "height"),
851
+ sheetTransform: getSheetTransform(record.hostContext),
852
+ allowTransform: getBoolean(record.hostContext, "allowTransform"),
853
+ resizeBehavior: getString(record.hostContext, "resizeBehavior") === "aspect-ratio" || ((_context$descriptor2 = context.descriptor) === null || _context$descriptor2 === void 0 ? void 0 : _context$descriptor2.childType) === _univerjs_core.UniverInstanceType.UNIVER_SLIDE ? "aspect-ratio" : void 0,
854
+ aspectRatio: (_getNumber = getNumber(record.hostContext, "aspectRatio")) !== null && _getNumber !== void 0 ? _getNumber : ((_context$descriptor3 = context.descriptor) === null || _context$descriptor3 === void 0 ? void 0 : _context$descriptor3.childType) === _univerjs_core.UniverInstanceType.UNIVER_SLIDE ? 16 / 9 : void 0
855
+ });
856
+ sheetSkeletonService === null || sheetSkeletonService === void 0 || sheetSkeletonService.ensureSkeleton(record.hostUnitId, hostSubUnitId);
857
+ const skeletonParam = sheetSkeletonService === null || sheetSkeletonService === void 0 ? void 0 : sheetSkeletonService.getSkeletonParam(record.hostUnitId, hostSubUnitId);
858
+ if (!skeletonParam) return;
859
+ const transform = drawingPositionToTransform(drawing.sheetTransform, skeletonParam);
860
+ if (!transform) return;
861
+ return {
862
+ ...drawing,
863
+ transform,
864
+ axisAlignSheetTransform: (_transformToAxisAlign = transformToAxisAlignPosition(transform, skeletonParam.skeleton)) !== null && _transformToAxisAlign !== void 0 ? _transformToAxisAlign : drawing.sheetTransform
865
+ };
866
+ }
867
+ function createRecord(context, kind, prefix) {
868
+ var _context$requestedAnc;
869
+ return {
870
+ hostAnchorId: (_context$requestedAnc = context.requestedAnchorId) !== null && _context$requestedAnc !== void 0 ? _context$requestedAnc : `${prefix}:${context.embedId}`,
871
+ embedId: context.embedId,
872
+ hostUnitId: context.hostUnitId,
873
+ hostType: context.hostType,
874
+ entry: context.entry,
875
+ kind,
876
+ hostContext: context.hostContext,
877
+ lifecycle: "active"
878
+ };
879
+ }
880
+ function createRecordOnlyRemovePlan(context, record) {
881
+ return {
882
+ redoMutations: [{
883
+ id: _univerjs_embed.REMOVE_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
884
+ params: {
885
+ hostUnitId: context.hostUnitId,
886
+ hostAnchorId: context.hostAnchorId
887
+ }
888
+ }],
889
+ undoMutations: [{
890
+ id: _univerjs_embed.SET_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
891
+ params: { record: {
892
+ ...record,
893
+ lifecycle: "active"
894
+ } }
895
+ }]
896
+ };
897
+ }
898
+ function getHostSubUnitId(hostContext) {
899
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext.subUnitId) === "string" ? hostContext.subUnitId : void 0;
900
+ }
901
+ function getNumber(hostContext, key) {
902
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "number" ? hostContext[key] : void 0;
903
+ }
904
+ function getString(hostContext, key) {
905
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "string" ? hostContext[key] : void 0;
906
+ }
907
+ function getBoolean(hostContext, key) {
908
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext[key]) === "boolean" ? hostContext[key] : void 0;
909
+ }
910
+ function getSheetTransform(hostContext) {
911
+ const value = hostContext === null || hostContext === void 0 ? void 0 : hostContext.sheetTransform;
912
+ if (!value || typeof value !== "object") return;
913
+ const candidate = value;
914
+ if (!candidate.from || !candidate.to) return;
915
+ return candidate;
916
+ }
917
+ function getSheetDrawingService(sheetDrawingService) {
918
+ return typeof sheetDrawingService === "function" ? sheetDrawingService() : sheetDrawingService;
919
+ }
920
+ function getDrawingManagerService(drawingManagerService) {
921
+ return typeof drawingManagerService === "function" ? drawingManagerService() : drawingManagerService;
922
+ }
923
+ function getSheetSkeletonService(sheetSkeletonService) {
924
+ return typeof sheetSkeletonService === "function" ? sheetSkeletonService() : sheetSkeletonService;
925
+ }
926
+ function requireAnchorPlan(plan, errorCode) {
927
+ if (!plan) throw new Error(errorCode);
928
+ return plan;
929
+ }
930
+ function requireAnchorRecord$1(record, errorCode) {
931
+ if (!record) throw new Error(errorCode);
932
+ return record;
933
+ }
934
+ function normalizeSheetsFloatingObjectHostContext(context) {
935
+ var _context$descriptor4, _getNumber2, _context$descriptor5;
936
+ const hostContext = context.hostContext;
937
+ const configuredResizeBehavior = getSheetsFloatingResizeBehavior(hostContext);
938
+ const resizeBehavior = configuredResizeBehavior === "aspect-ratio" || ((_context$descriptor4 = context.descriptor) === null || _context$descriptor4 === void 0 ? void 0 : _context$descriptor4.childType) === _univerjs_core.UniverInstanceType.UNIVER_SLIDE ? "aspect-ratio" : configuredResizeBehavior;
939
+ const aspectRatio = (_getNumber2 = getNumber(hostContext, "aspectRatio")) !== null && _getNumber2 !== void 0 ? _getNumber2 : ((_context$descriptor5 = context.descriptor) === null || _context$descriptor5 === void 0 ? void 0 : _context$descriptor5.childType) === _univerjs_core.UniverInstanceType.UNIVER_SLIDE ? 16 / 9 : void 0;
940
+ if (resizeBehavior !== "aspect-ratio" || aspectRatio == null) return hostContext;
941
+ const size = resolveEmbedSheetsFloatingObjectSize({
942
+ width: getNumber(hostContext, "width"),
943
+ height: getNumber(hostContext, "height"),
944
+ resizeBehavior,
945
+ aspectRatio
946
+ });
947
+ return {
948
+ ...hostContext,
949
+ width: size.width,
950
+ height: size.height,
951
+ resizeBehavior,
952
+ aspectRatio
953
+ };
954
+ }
955
+ function getSheetsFloatingResizeBehavior(hostContext) {
956
+ const value = getString(hostContext, "resizeBehavior");
957
+ return value === "free" || value === "aspect-ratio" || value === "height-auto" || value === "disabled" ? value : void 0;
958
+ }
959
+ function toSetDrawingMutation(jsonOp, type, direction) {
960
+ return {
961
+ id: SetDrawingApplyMutation.id,
962
+ params: {
963
+ unitId: jsonOp.unitId,
964
+ subUnitId: jsonOp.subUnitId,
965
+ op: direction === "redo" ? jsonOp.redo : jsonOp.undo,
966
+ objects: jsonOp.objects,
967
+ type
968
+ }
969
+ };
970
+ }
971
+
972
+ //#endregion
973
+ //#region src/embed-tab-anchor.ts
974
+ const EMBED_SHEETS_TAB_CUSTOM_KEY = "UNIVER_EMBED_SHEETS_TAB";
975
+ function createEmbedSheetsTabSnapshot(params) {
976
+ var _params$name;
977
+ return {
978
+ id: params.hostAnchorId,
979
+ name: (_params$name = params.name) !== null && _params$name !== void 0 ? _params$name : params.embedId,
980
+ tabColor: "",
981
+ hidden: _univerjs_core.BooleanNumber.FALSE,
982
+ rowCount: 1,
983
+ columnCount: 1,
984
+ zoomRatio: 1,
985
+ freeze: {
986
+ startRow: -1,
987
+ startColumn: -1,
988
+ ySplit: 0,
989
+ xSplit: 0
990
+ },
991
+ scrollTop: 0,
992
+ scrollLeft: 0,
993
+ defaultColumnWidth: 88,
994
+ defaultRowHeight: 24,
995
+ mergeData: [],
996
+ cellData: {},
997
+ rowData: {},
998
+ columnData: {},
999
+ showGridlines: _univerjs_core.BooleanNumber.FALSE,
1000
+ rowHeader: {
1001
+ width: 46,
1002
+ hidden: _univerjs_core.BooleanNumber.TRUE
1003
+ },
1004
+ columnHeader: {
1005
+ height: 20,
1006
+ hidden: _univerjs_core.BooleanNumber.TRUE
1007
+ },
1008
+ rightToLeft: _univerjs_core.BooleanNumber.FALSE,
1009
+ custom: { [EMBED_SHEETS_TAB_CUSTOM_KEY]: createEmbedSheetsTabCustomData(params) }
1010
+ };
1011
+ }
1012
+ function createEmbedSheetsTabCustomData(params) {
1013
+ return {
1014
+ version: 1,
1015
+ embedId: params.embedId,
1016
+ hostAnchorId: params.hostAnchorId
1017
+ };
1018
+ }
1019
+ function createEmbedSheetsTabSnapshotFromDescriptor(descriptor, name) {
1020
+ return createEmbedSheetsTabSnapshot({
1021
+ embedId: descriptor.embedId,
1022
+ hostAnchorId: descriptor.hostAnchorId,
1023
+ name
1024
+ });
1025
+ }
1026
+ function getEmbedSheetsTabCustomData(snapshot) {
1027
+ var _snapshot$custom;
1028
+ const value = (_snapshot$custom = snapshot.custom) === null || _snapshot$custom === void 0 ? void 0 : _snapshot$custom[EMBED_SHEETS_TAB_CUSTOM_KEY];
1029
+ if (!isEmbedSheetsTabCustomData(value)) return;
1030
+ return value;
1031
+ }
1032
+ function isEmbedSheetsTabSnapshot(snapshot) {
1033
+ return getEmbedSheetsTabCustomData(snapshot) != null;
1034
+ }
1035
+ function isEmbedSheetsTabCustomData(value) {
1036
+ if (!value || typeof value !== "object") return false;
1037
+ const candidate = value;
1038
+ return candidate.version === 1 && typeof candidate.embedId === "string" && typeof candidate.hostAnchorId === "string";
1039
+ }
1040
+
1041
+ //#endregion
1042
+ //#region src/embed-tab-host-adapter.ts
1043
+ function registerSheetsSheetTabEmbedHostAdapters(injector) {
1044
+ (0, _univerjs_embed.registerEmbedHostAdapterContributions)(injector, [createSheetsSheetTabHostAdapterContribution(injector.has(_univerjs_embed.EmbedHostAnchorModelService) ? injector.get(_univerjs_embed.EmbedHostAnchorModelService) : void 0, injector.has(_univerjs_core.IUniverInstanceService) ? injector.get(_univerjs_core.IUniverInstanceService) : void 0)]);
1045
+ }
1046
+ function createSheetsSheetTabHostAdapterContribution(anchorModelService, univerInstanceService) {
1047
+ return {
1048
+ hostType: _univerjs_core.UniverInstanceType.UNIVER_SHEET,
1049
+ entry: "sheets-sheet-tab",
1050
+ createAnchorPlan: createSheetsSheetTabAnchorPlan,
1051
+ restoreAnchor: (context) => requireAnchorRecord(restoreSheetsSheetTabAnchor(context, univerInstanceService), "EMBED_SHEETS_TAB_ANCHOR_UNAVAILABLE"),
1052
+ removeAnchorPlan: (context) => {
1053
+ var _anchorModelService$g;
1054
+ return createSheetsSheetTabRemoveAnchorPlan(context, (_anchorModelService$g = anchorModelService === null || anchorModelService === void 0 ? void 0 : anchorModelService.getAnchor(context.hostUnitId, context.hostAnchorId)) !== null && _anchorModelService$g !== void 0 ? _anchorModelService$g : createSheetsSheetTabRecord(context));
1055
+ },
1056
+ activateAnchor: (context) => {
1057
+ var _workbook$getSheetByS;
1058
+ const workbook = univerInstanceService === null || univerInstanceService === void 0 ? void 0 : univerInstanceService.getUnit(context.hostUnitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1059
+ const worksheet = workbook === null || workbook === void 0 || (_workbook$getSheetByS = workbook.getSheetBySheetId) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.call(workbook, context.hostAnchorId);
1060
+ if (worksheet) {
1061
+ var _workbook$setActiveSh;
1062
+ workbook === null || workbook === void 0 || (_workbook$setActiveSh = workbook.setActiveSheet) === null || _workbook$setActiveSh === void 0 || _workbook$setActiveSh.call(workbook, worksheet);
1063
+ }
1064
+ }
1065
+ };
1066
+ }
1067
+ function createSheetsSheetTabAnchorPlan(context) {
1068
+ var _getSheetName;
1069
+ const record = createSheetsSheetTabRecord(context);
1070
+ const sheetIndex = getSheetIndex(record.hostContext);
1071
+ const sheetName = (_getSheetName = getSheetName(record.hostContext)) !== null && _getSheetName !== void 0 ? _getSheetName : context.embedId;
1072
+ const sheet = createEmbedSheetsTabSnapshot({
1073
+ embedId: record.embedId,
1074
+ hostAnchorId: record.hostAnchorId,
1075
+ name: sheetName
1076
+ });
1077
+ return {
1078
+ hostAnchorId: record.hostAnchorId,
1079
+ redoMutations: [{
1080
+ id: _univerjs_sheets.InsertSheetMutation.id,
1081
+ params: {
1082
+ unitId: record.hostUnitId,
1083
+ index: sheetIndex,
1084
+ sheet
1085
+ }
1086
+ }, {
1087
+ id: _univerjs_embed.SET_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
1088
+ params: { record }
1089
+ }],
1090
+ undoMutations: [{
1091
+ id: _univerjs_embed.REMOVE_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
1092
+ params: {
1093
+ hostUnitId: record.hostUnitId,
1094
+ hostAnchorId: record.hostAnchorId
1095
+ }
1096
+ }, {
1097
+ id: _univerjs_sheets.RemoveSheetMutation.id,
1098
+ params: {
1099
+ unitId: record.hostUnitId,
1100
+ subUnitId: record.hostAnchorId,
1101
+ subUnitName: sheet.name
1102
+ }
1103
+ }]
1104
+ };
1105
+ }
1106
+ function createSheetsSheetTabRemoveAnchorPlan(context, record) {
1107
+ var _getSheetName2;
1108
+ const sheetIndex = getSheetIndex(record.hostContext);
1109
+ const sheetName = (_getSheetName2 = getSheetName(record.hostContext)) !== null && _getSheetName2 !== void 0 ? _getSheetName2 : record.embedId;
1110
+ const sheet = createEmbedSheetsTabSnapshot({
1111
+ embedId: record.embedId,
1112
+ hostAnchorId: record.hostAnchorId,
1113
+ name: sheetName
1114
+ });
1115
+ return {
1116
+ redoMutations: [{
1117
+ id: _univerjs_embed.REMOVE_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
1118
+ params: {
1119
+ hostUnitId: context.hostUnitId,
1120
+ hostAnchorId: context.hostAnchorId
1121
+ }
1122
+ }, {
1123
+ id: _univerjs_sheets.RemoveSheetMutation.id,
1124
+ params: {
1125
+ unitId: context.hostUnitId,
1126
+ subUnitId: context.hostAnchorId,
1127
+ subUnitName: sheet.name
1128
+ }
1129
+ }],
1130
+ undoMutations: [{
1131
+ id: _univerjs_sheets.InsertSheetMutation.id,
1132
+ params: {
1133
+ unitId: context.hostUnitId,
1134
+ index: sheetIndex,
1135
+ sheet
1136
+ }
1137
+ }, {
1138
+ id: _univerjs_embed.SET_EMBED_HOST_ANCHOR_RECORD_MUTATION_ID,
1139
+ params: { record: {
1140
+ ...record,
1141
+ lifecycle: "active"
1142
+ } }
1143
+ }]
1144
+ };
1145
+ }
1146
+ function restoreSheetsSheetTabAnchor(context, univerInstanceService) {
1147
+ var _getSheetName3, _workbook$getSheetByS2;
1148
+ const workbook = getWorkbook(univerInstanceService, context.hostUnitId);
1149
+ if (!workbook) return;
1150
+ const record = createSheetsSheetTabRecord({
1151
+ ...context,
1152
+ requestedAnchorId: context.hostAnchorId
1153
+ });
1154
+ const sheetName = (_getSheetName3 = getSheetName(record.hostContext)) !== null && _getSheetName3 !== void 0 ? _getSheetName3 : context.embedId;
1155
+ const sheetIndex = getSheetIndex(record.hostContext);
1156
+ if (!((_workbook$getSheetByS2 = workbook.getSheetBySheetId) === null || _workbook$getSheetByS2 === void 0 ? void 0 : _workbook$getSheetByS2.call(workbook, record.hostAnchorId))) {
1157
+ var _workbook$getActiveSh;
1158
+ const activeWorksheet = (_workbook$getActiveSh = workbook.getActiveSheet) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.call(workbook, true);
1159
+ workbook.addWorksheet(record.hostAnchorId, sheetIndex, createEmbedSheetsTabSnapshot({
1160
+ embedId: record.embedId,
1161
+ hostAnchorId: record.hostAnchorId,
1162
+ name: sheetName
1163
+ }));
1164
+ if (activeWorksheet) {
1165
+ var _workbook$setActiveSh2;
1166
+ (_workbook$setActiveSh2 = workbook.setActiveSheet) === null || _workbook$setActiveSh2 === void 0 || _workbook$setActiveSh2.call(workbook, activeWorksheet);
1167
+ }
1168
+ }
1169
+ return {
1170
+ ...record,
1171
+ hostContext: {
1172
+ ...record.hostContext,
1173
+ sheetIndex,
1174
+ sheetName
1175
+ }
1176
+ };
1177
+ }
1178
+ function createSheetsSheetTabRecord(context) {
1179
+ var _context$requestedAnc, _getSheetName4;
1180
+ const hostAnchorId = (_context$requestedAnc = context.requestedAnchorId) !== null && _context$requestedAnc !== void 0 ? _context$requestedAnc : `sheets-tab:${context.embedId}`;
1181
+ return {
1182
+ hostAnchorId,
1183
+ embedId: context.embedId,
1184
+ hostUnitId: context.hostUnitId,
1185
+ hostType: context.hostType,
1186
+ entry: context.entry,
1187
+ kind: "sheets-sheet-tab",
1188
+ hostContext: {
1189
+ ...context.hostContext,
1190
+ sheetIndex: getSheetIndex(context.hostContext),
1191
+ sheetName: (_getSheetName4 = getSheetName(context.hostContext)) !== null && _getSheetName4 !== void 0 ? _getSheetName4 : context.embedId,
1192
+ sheetTab: createEmbedSheetsTabCustomData({
1193
+ embedId: context.embedId,
1194
+ hostAnchorId
1195
+ })
1196
+ },
1197
+ lifecycle: "active"
1198
+ };
1199
+ }
1200
+ function getSheetIndex(hostContext) {
1201
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext.sheetIndex) === "number" ? hostContext.sheetIndex : Number.MAX_SAFE_INTEGER;
1202
+ }
1203
+ function getSheetName(hostContext) {
1204
+ return typeof (hostContext === null || hostContext === void 0 ? void 0 : hostContext.sheetName) === "string" ? hostContext.sheetName : void 0;
1205
+ }
1206
+ function requireAnchorRecord(record, errorCode) {
1207
+ if (!record) throw new Error(errorCode);
1208
+ return record;
1209
+ }
1210
+ function getWorkbook(univerInstanceService, unitId) {
1211
+ return univerInstanceService === null || univerInstanceService === void 0 ? void 0 : univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1212
+ }
1213
+
584
1214
  //#endregion
585
1215
  //#region package.json
586
1216
  var name = "@univerjs/sheets-drawing";
587
- var version = "1.0.0-alpha.1";
1217
+ var version = "1.0.0-insiders.20260701-0ef51b0";
588
1218
 
589
1219
  //#endregion
590
1220
  //#region src/config/config.ts
@@ -663,6 +1293,8 @@ let UniverSheetsDrawingPlugin = class UniverSheetsDrawingPlugin extends _univerj
663
1293
  onStarting() {
664
1294
  [[SheetsDrawingLoadController], [ISheetDrawingService, { useClass: SheetDrawingService }]].forEach((dependency) => this._injector.add(dependency));
665
1295
  this._injector.get(SheetsDrawingLoadController);
1296
+ registerSheetsDrawingEmbedHostAdapters(this._injector);
1297
+ registerSheetsSheetTabEmbedHostAdapters(this._injector);
666
1298
  }
667
1299
  };
668
1300
  _defineProperty(UniverSheetsDrawingPlugin, "pluginName", SHEET_DRAWING_PLUGIN);
@@ -678,6 +1310,8 @@ UniverSheetsDrawingPlugin = __decorate([
678
1310
  //#endregion
679
1311
  exports.ClearSheetDrawingTransformerOperation = ClearSheetDrawingTransformerOperation;
680
1312
  exports.DrawingApplyType = DrawingApplyType;
1313
+ exports.EMBED_SHEETS_FLOATING_COMPONENT_KEY = EMBED_SHEETS_FLOATING_COMPONENT_KEY;
1314
+ exports.EMBED_SHEETS_TAB_CUSTOM_KEY = EMBED_SHEETS_TAB_CUSTOM_KEY;
681
1315
  exports.ISheetDrawingService = ISheetDrawingService;
682
1316
  exports.InsertSheetDrawingCommand = InsertSheetDrawingCommand;
683
1317
  exports.RemoveSheetDrawingCommand = RemoveSheetDrawingCommand;
@@ -692,6 +1326,21 @@ Object.defineProperty(exports, 'UniverSheetsDrawingPlugin', {
692
1326
  return UniverSheetsDrawingPlugin;
693
1327
  }
694
1328
  });
1329
+ exports.createEmbedSheetsFloatingDrawing = createEmbedSheetsFloatingDrawing;
1330
+ exports.createEmbedSheetsFloatingDrawingFromDescriptor = createEmbedSheetsFloatingDrawingFromDescriptor;
1331
+ exports.createEmbedSheetsFloatingObjectData = createEmbedSheetsFloatingObjectData;
1332
+ exports.createEmbedSheetsTabCustomData = createEmbedSheetsTabCustomData;
1333
+ exports.createEmbedSheetsTabSnapshot = createEmbedSheetsTabSnapshot;
1334
+ exports.createEmbedSheetsTabSnapshotFromDescriptor = createEmbedSheetsTabSnapshotFromDescriptor;
1335
+ exports.createSheetsFloatingObjectHostAdapterContribution = createSheetsFloatingObjectHostAdapterContribution;
1336
+ exports.createSheetsSheetTabHostAdapterContribution = createSheetsSheetTabHostAdapterContribution;
695
1337
  exports.drawingPositionToTransform = drawingPositionToTransform;
1338
+ exports.getEmbedSheetsFloatingObjectData = getEmbedSheetsFloatingObjectData;
1339
+ exports.getEmbedSheetsTabCustomData = getEmbedSheetsTabCustomData;
1340
+ exports.isEmbedSheetsFloatingDrawing = isEmbedSheetsFloatingDrawing;
1341
+ exports.isEmbedSheetsTabSnapshot = isEmbedSheetsTabSnapshot;
1342
+ exports.registerSheetsDrawingEmbedHostAdapters = registerSheetsDrawingEmbedHostAdapters;
1343
+ exports.registerSheetsSheetTabEmbedHostAdapters = registerSheetsSheetTabEmbedHostAdapters;
1344
+ exports.resolveEmbedSheetsFloatingObjectSize = resolveEmbedSheetsFloatingObjectSize;
696
1345
  exports.transformToAxisAlignPosition = transformToAxisAlignPosition;
697
1346
  exports.transformToDrawingPosition = transformToDrawingPosition;