@quadrats/react 1.0.0 → 1.1.1

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.
Files changed (119) hide show
  1. package/card/components/Card.js +83 -75
  2. package/card/index.cjs.js +82 -74
  3. package/carousel/components/Carousel.js +32 -28
  4. package/carousel/index.cjs.js +32 -28
  5. package/components/Tooltip/index.js +5 -2
  6. package/components/index.cjs.js +5 -2
  7. package/core/components/Quadrats.js +5 -2
  8. package/core/contexts/modal/CarouselModal/CarouselModal.js +14 -17
  9. package/embed/renderers/base/components/BaseEmbedElement.js +51 -43
  10. package/embed/renderers/base/index.cjs.js +50 -42
  11. package/image/components/Image.js +34 -26
  12. package/image/createReactImage.js +1 -1
  13. package/image/index.cjs.js +34 -26
  14. package/index.cjs.js +19 -19
  15. package/package.json +4 -4
  16. package/table/components/ColumnDragButton.d.ts +10 -0
  17. package/table/components/ColumnDragButton.js +41 -0
  18. package/table/components/RowDragButton.d.ts +10 -0
  19. package/table/components/RowDragButton.js +42 -0
  20. package/table/components/Table.d.ts +9 -0
  21. package/table/components/Table.js +236 -0
  22. package/table/components/TableBody.d.ts +5 -0
  23. package/table/components/TableBody.js +8 -0
  24. package/table/components/TableCell.d.ts +5 -0
  25. package/table/components/TableCell.js +297 -0
  26. package/table/components/TableDragLayer.d.ts +6 -0
  27. package/table/components/TableDragLayer.js +89 -0
  28. package/table/components/TableHeader.d.ts +5 -0
  29. package/table/components/TableHeader.js +13 -0
  30. package/table/components/TableMain.d.ts +5 -0
  31. package/table/components/TableMain.js +233 -0
  32. package/table/components/TableRow.d.ts +5 -0
  33. package/table/components/TableRow.js +8 -0
  34. package/table/components/TableTitle.d.ts +5 -0
  35. package/table/components/TableTitle.js +18 -0
  36. package/table/contexts/TableActionsContext.d.ts +3 -0
  37. package/table/contexts/TableActionsContext.js +5 -0
  38. package/table/contexts/TableDragContext.d.ts +26 -0
  39. package/table/contexts/TableDragContext.js +26 -0
  40. package/table/contexts/TableHeaderContext.d.ts +2 -0
  41. package/table/contexts/TableHeaderContext.js +7 -0
  42. package/table/contexts/TableMetadataContext.d.ts +3 -0
  43. package/table/contexts/TableMetadataContext.js +5 -0
  44. package/table/contexts/TableScrollContext.d.ts +2 -0
  45. package/table/contexts/TableScrollContext.js +9 -0
  46. package/table/contexts/TableStateContext.d.ts +3 -0
  47. package/table/contexts/TableStateContext.js +5 -0
  48. package/table/createReactTable.d.ts +4 -0
  49. package/table/createReactTable.js +297 -0
  50. package/table/defaultRenderTableElements.d.ts +2 -0
  51. package/table/defaultRenderTableElements.js +20 -0
  52. package/table/hooks/useColumnResize.d.ts +12 -0
  53. package/table/hooks/useColumnResize.js +168 -0
  54. package/table/hooks/useTableActions.d.ts +27 -0
  55. package/table/hooks/useTableActions.js +1092 -0
  56. package/table/hooks/useTableActionsContext.d.ts +1 -0
  57. package/table/hooks/useTableActionsContext.js +12 -0
  58. package/table/hooks/useTableCell.d.ts +16 -0
  59. package/table/hooks/useTableCell.js +166 -0
  60. package/table/hooks/useTableCellToolbarActions.d.ts +34 -0
  61. package/table/hooks/useTableCellToolbarActions.js +526 -0
  62. package/table/hooks/useTableMetadata.d.ts +1 -0
  63. package/table/hooks/useTableMetadata.js +12 -0
  64. package/table/hooks/useTableStateContext.d.ts +1 -0
  65. package/table/hooks/useTableStateContext.js +12 -0
  66. package/table/hooks/useTableStates.d.ts +18 -0
  67. package/table/hooks/useTableStates.js +14 -0
  68. package/table/index.cjs.js +4002 -0
  69. package/table/index.d.ts +16 -0
  70. package/table/index.js +27 -0
  71. package/table/jsx-serializer/components/Table.d.ts +3 -0
  72. package/table/jsx-serializer/components/Table.js +7 -0
  73. package/table/jsx-serializer/components/TableBody.d.ts +3 -0
  74. package/table/jsx-serializer/components/TableBody.js +7 -0
  75. package/table/jsx-serializer/components/TableCell.d.ts +5 -0
  76. package/table/jsx-serializer/components/TableCell.js +33 -0
  77. package/table/jsx-serializer/components/TableHeader.d.ts +3 -0
  78. package/table/jsx-serializer/components/TableHeader.js +10 -0
  79. package/table/jsx-serializer/components/TableMain.d.ts +6 -0
  80. package/table/jsx-serializer/components/TableMain.js +18 -0
  81. package/table/jsx-serializer/components/TableRow.d.ts +3 -0
  82. package/table/jsx-serializer/components/TableRow.js +7 -0
  83. package/table/jsx-serializer/components/TableTitle.d.ts +3 -0
  84. package/table/jsx-serializer/components/TableTitle.js +7 -0
  85. package/table/jsx-serializer/contexts/TableHeaderContext.d.ts +1 -0
  86. package/table/jsx-serializer/contexts/TableHeaderContext.js +5 -0
  87. package/table/jsx-serializer/contexts/TableScrollContext.d.ts +2 -0
  88. package/table/jsx-serializer/contexts/TableScrollContext.js +7 -0
  89. package/table/jsx-serializer/createJsxSerializeTable.d.ts +5 -0
  90. package/table/jsx-serializer/createJsxSerializeTable.js +113 -0
  91. package/table/jsx-serializer/defaultRenderTableElements.d.ts +2 -0
  92. package/table/jsx-serializer/defaultRenderTableElements.js +20 -0
  93. package/table/jsx-serializer/index.cjs.js +195 -0
  94. package/table/jsx-serializer/index.d.ts +3 -0
  95. package/table/jsx-serializer/index.js +2 -0
  96. package/table/jsx-serializer/package.json +7 -0
  97. package/table/jsx-serializer/typings.d.ts +12 -0
  98. package/table/package.json +10 -0
  99. package/table/table.css +1 -0
  100. package/table/table.scss +428 -0
  101. package/table/toolbar/TableToolbarIcon.d.ts +8 -0
  102. package/table/toolbar/TableToolbarIcon.js +12 -0
  103. package/table/toolbar/index.cjs.js +24 -0
  104. package/table/toolbar/index.d.ts +2 -0
  105. package/table/toolbar/index.js +2 -0
  106. package/table/toolbar/package.json +7 -0
  107. package/table/toolbar/useTableTool.d.ts +4 -0
  108. package/table/toolbar/useTableTool.js +13 -0
  109. package/table/typings.d.ts +68 -0
  110. package/table/utils/helper.d.ts +186 -0
  111. package/table/utils/helper.js +799 -0
  112. package/toolbar/components/InlineToolbar.d.ts +12 -11
  113. package/toolbar/components/InlineToolbar.js +23 -19
  114. package/toolbar/components/Toolbar.js +2 -2
  115. package/toolbar/index.cjs.js +24 -21
  116. package/toolbar/toolbar.css +1 -1
  117. package/toolbar/toolbar.scss +4 -1
  118. package/utils/index.cjs.js +7 -1
  119. package/utils/removePreviousElement.js +7 -1
@@ -0,0 +1,186 @@
1
+ import { Element } from '@quadrats/core';
2
+ import { TableElement, ColumnWidth } from '@quadrats/common/table';
3
+ import { QuadratsReactEditor } from '@quadrats/react';
4
+ import { AlignValue } from '@quadrats/common/align';
5
+ /**
6
+ * 分配百分比寬度,確保總和為 100%
7
+ * 前 n-1 個欄位使用四捨五入的平均值,最後一個欄位使用剩餘寬度
8
+ * @param count - 欄位數量
9
+ * @returns 百分比陣列,總和為 100%
10
+ */
11
+ export declare function distributeEqualPercentages(count: number): number[];
12
+ /**
13
+ * 等比例縮減現有百分比並加入新欄位
14
+ * 前 n-1 個縮減後的欄位使用四捨五入,最後一個縮減欄位使用剩餘寬度
15
+ * @param currentPercentages - 當前的百分比陣列
16
+ * @param newColumnPercentage - 新欄位要佔的百分比
17
+ * @param insertIndex - 新欄位插入的位置(0-based)
18
+ * @returns 新的百分比陣列,總和為 100%
19
+ */
20
+ export declare function scalePercentagesWithNewColumn(currentPercentages: number[], newColumnPercentage: number, insertIndex: number): number[];
21
+ export interface TableElements {
22
+ tableMainElement: TableElement | null;
23
+ tableBodyElement: TableElement | null;
24
+ tableHeaderElement: TableElement | null;
25
+ }
26
+ export interface TablePaths {
27
+ tableMainPath: number[];
28
+ tableBodyPath: number[];
29
+ tableHeaderPath: number[] | null;
30
+ }
31
+ export interface TableStructure extends TableElements, TablePaths {
32
+ headerRowCount: number;
33
+ columnCount: number;
34
+ firstRow: Element | null;
35
+ }
36
+ /**
37
+ * 提取表格的所有基本元素
38
+ */
39
+ export declare function getTableElements(element: TableElement): TableElements;
40
+ /**
41
+ * 獲取表格的完整結構
42
+ */
43
+ export declare function getTableStructure(editor: QuadratsReactEditor, element: TableElement): TableStructure | null;
44
+ /**
45
+ * 檢查列是否有 pinned cells
46
+ */
47
+ export declare function hasColumnPinnedCells(tableStructure: TableStructure, columnIndex: number): boolean;
48
+ /**
49
+ * 檢查是否有任何 pinned columns
50
+ */
51
+ export declare function hasAnyPinnedColumns(tableStructure: TableStructure): boolean;
52
+ /**
53
+ * 檢查是否有任何 pinned rows
54
+ */
55
+ export declare function hasAnyPinnedRows(tableStructure: TableStructure): boolean;
56
+ /**
57
+ * 創建新的 table cell
58
+ */
59
+ export declare function createTableCell(referenceCell?: TableElement, overrideProps?: Partial<TableElement>): TableElement;
60
+ /**
61
+ * 獲取參考 row
62
+ */
63
+ export declare function getReferenceRowFromHeaderOrBody(HeaderOrBodyContainer: TableElement, rowIndex: number): TableElement | undefined;
64
+ /**
65
+ * 收集指定範圍的 cells
66
+ * @param tableStructure - 表格結構
67
+ * @param scope - 'table' | 'column'
68
+ * @param columnIndex - 當 scope 為 'column' 時需要指定
69
+ * @returns cells 陣列
70
+ */
71
+ export declare function collectCells(tableStructure: TableStructure, scope: 'table' | 'column', columnIndex?: number): Element[];
72
+ /**
73
+ * 設定指定 cells 的 align
74
+ * @param editor - Slate editor
75
+ * @param cells - 要設定 align 的 cell 元素陣列
76
+ * @param alignValue - align 值
77
+ */
78
+ export declare function setAlignForCells(editor: QuadratsReactEditor, cells: Element[], alignValue: AlignValue): void;
79
+ /**
80
+ * 獲取指定 cells 的 align 狀態
81
+ * @param cells - 要檢查的 cell 元素陣列
82
+ * @returns 如果所有 cell 的 align 都相同則返回該值,否則返回 'left'
83
+ */
84
+ export declare function getAlignFromCells(cells: Element[]): AlignValue;
85
+ /**
86
+ * 獲取釘選欄位的資訊
87
+ * @param tableElement - 表格最外層元素
88
+ * @returns 釘選欄位的索引陣列和總寬度百分比
89
+ */
90
+ export declare function getPinnedColumnsInfo(tableElement: TableElement): {
91
+ pinnedColumnIndices: number[];
92
+ totalPinnedPercentage: number;
93
+ };
94
+ /**
95
+ * 強制調整釘選欄位寬度以符合最大限制
96
+ * @param columnWidths - 當前欄位寬度陣列
97
+ * @param pinnedColumnIndices - 釘選欄位索引陣列
98
+ * @returns 調整後的欄位寬度陣列
99
+ */
100
+ export declare function enforcePinnedColumnsMaxWidth(columnWidths: ColumnWidth[], pinnedColumnIndices: number[]): ColumnWidth[];
101
+ /**
102
+ * 獲取表格的欄位寬度陣列
103
+ * 當有釘選欄位時:
104
+ * - 釘選欄位使用 percentage
105
+ * - 未釘選欄位使用 pixel(基於剩餘空間平均分配)
106
+ * @param tableElement - 表格最外層元素
107
+ * @param tableWidth - 表格容器的實際寬度(pixel),用於計算 pixel 寬度
108
+ * @returns 欄位寬度陣列
109
+ */
110
+ export declare function getColumnWidths(tableElement: TableElement, tableWidth?: number): ColumnWidth[];
111
+ /**
112
+ * 設定表格的欄位寬度
113
+ * @param editor - Slate editor
114
+ * @param tableElement - 表格最外層元素
115
+ * @param columnWidths - 欄位寬度陣列
116
+ */
117
+ export declare function setColumnWidths(editor: QuadratsReactEditor, tableElement: TableElement, columnWidths: ColumnWidth[]): void;
118
+ /**
119
+ * 計算新增欄位後的欄位寬度
120
+ * - 如果所有欄位都是 percentage:按比例縮減現有欄位,新欄位佔平均寬度
121
+ * - 如果有混合模式(percentage + pixel):
122
+ * * 如果用戶操作的欄位是 pinned column:新欄位使用 percentage(需要調整 pinned columns 的百分比)
123
+ * * 如果用戶操作的欄位是 unpinned column:新欄位使用 pixel(與其他 pixel 欄位相同寬度)
124
+ *
125
+ * @param currentWidths - 當前的欄位寬度陣列
126
+ * @param insertIndex - 新欄位插入的位置(0-based)
127
+ * @param pinnedColumnIndices - 當前釘選欄位的索引陣列(插入前的索引)
128
+ * @param operatingColumnIndex - 用戶實際操作的欄位索引(用於判斷是在 pinned 還是 unpinned column 操作)
129
+ * @returns 新的欄位寬度陣列
130
+ */
131
+ export declare function calculateColumnWidthsAfterAdd(currentWidths: ColumnWidth[], insertIndex: number, pinnedColumnIndices?: number[], operatingColumnIndex?: number): ColumnWidth[];
132
+ /**
133
+ * 計算刪除欄位後的欄位寬度
134
+ * 此函數會智慧處理欄位寬度的重新分配:
135
+ * - 如果所有欄位都是 percentage:按比例放大剩餘欄位
136
+ * - 如果有 pixel 欄位:保持 pixel 欄位不變,只調整 percentage 欄位
137
+ *
138
+ * @param currentWidths - 當前的欄位寬度陣列
139
+ * @param deleteIndex - 要刪除的欄位索引(0-based)
140
+ * @returns 新的欄位寬度陣列
141
+ */
142
+ export declare function calculateColumnWidthsAfterDelete(currentWidths: ColumnWidth[], deleteIndex: number): ColumnWidth[];
143
+ /**
144
+ * 計算拖曳後的欄位寬度
145
+ * 處理釘選欄位的特殊邏輯:
146
+ * - 情況 1:未釘選欄位(pixel)與未釘選欄位(pixel)之間:直接改變 pixel 值,允許超出容器
147
+ * - 情況 2:釘選欄位(percentage)與釘選欄位(percentage)之間:互相調整,且總和不超過 40%
148
+ * - 情況 3:釘選欄位(percentage)與未釘選欄位(pixel)之間:
149
+ * * 只調整釘選欄位的百分比(不超過 40% 總限制)
150
+ * * 當 table 未溢出(寬度 < container)時,重新計算所有未釘選欄位的 pixel 值以維持 100%
151
+ * * 當 table 已溢出時,只調整下一個欄位的 pixel 值
152
+ * * 當達到 40% 上限時,停止調整
153
+ * - 預設情況:兩個都是 percentage 但都不是釘選欄位(正常模式)
154
+ *
155
+ * @param currentWidths - 當前的欄位寬度陣列
156
+ * @param columnIndex - 被調整的欄位索引
157
+ * @param deltaPercentage - 寬度變化量(百分比)
158
+ * @param deltaPixel - 寬度變化量(pixel)
159
+ * @param pinnedColumnIndices - 釘選欄位的索引陣列
160
+ * @returns 新的欄位寬度陣列
161
+ */
162
+ export declare function calculateResizedColumnWidths(currentWidths: ColumnWidth[], columnIndex: number, deltaPercentage: number, deltaPixel: number, pinnedColumnIndices?: number[]): ColumnWidth[];
163
+ /**
164
+ * 移動或交換欄位寬度設定
165
+ * @param currentWidths - 當前的欄位寬度陣列
166
+ * @param sourceIndex - 來源欄位的索引
167
+ * @param targetIndex - 目標欄位的索引
168
+ * @param mode - 'swap' 為交換兩個位置,'move' 為移動到目標位置
169
+ * @returns 處理後的欄位寬度陣列
170
+ */
171
+ export declare function moveOrSwapColumnWidth(currentWidths: ColumnWidth[], sourceIndex: number, targetIndex: number, mode?: 'swap' | 'move'): ColumnWidth[];
172
+ /**
173
+ * 將 columnWidths 轉換為混合模式(釘選欄位用 percentage,未釘選欄位用 pixel)
174
+ * @param currentWidths - 當前的欄位寬度陣列
175
+ * @param pinnedColumnIndices - 釘選欄位的索引陣列
176
+ * @param tableWidth - 表格的實際寬度(pixel)
177
+ * @returns 轉換後的欄位寬度陣列
178
+ */
179
+ export declare function convertToMixedWidthMode(currentWidths: ColumnWidth[], pinnedColumnIndices: number[], tableWidth: number): ColumnWidth[];
180
+ /**
181
+ * 將混合模式的欄位寬度轉換回純百分比模式
182
+ * 當所有 pinned columns 都被 unpin 後,需要將 pixel 欄位轉換回 percentage
183
+ * @param currentWidths - 當前的欄位寬度陣列(混合模式)
184
+ * @returns 轉換後的純百分比欄位寬度陣列,總和為 100%
185
+ */
186
+ export declare function convertToPercentageMode(currentWidths: ColumnWidth[]): ColumnWidth[];