roosterjs-content-model-api 9.41.0 → 9.42.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,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns <= 4, width = 120px; if columns <= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertTable = void 0;
4
+ var tslib_1 = require("tslib");
4
5
  var adjustIndentation_1 = require("../../modelApi/common/adjustIndentation");
5
6
  var createTableStructure_1 = require("../../modelApi/table/createTableStructure");
6
7
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
@@ -10,10 +11,10 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
10
11
  * @param columns Number of columns in table, it also controls the default table cell width:
11
12
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
12
13
  * @param rows Number of rows in table
13
- * @param format (Optional) The table format. If not passed, the default format will be applied:
14
- * background color: #FFF; border color: #ABABAB
14
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
15
+ * @param format (Optional) The table format used for style attributes
15
16
  */
16
- function insertTable(editor, columns, rows, format) {
17
+ function insertTable(editor, columns, rows, tableMetadataFormat, format) {
17
18
  editor.focus();
18
19
  editor.formatContentModel(function (model, context) {
19
20
  var _a, _b, _c;
@@ -21,11 +22,14 @@ function insertTable(editor, columns, rows, format) {
21
22
  if (insertPosition) {
22
23
  var doc = (0, roosterjs_content_model_dom_1.createContentModelDocument)();
23
24
  var table = (0, createTableStructure_1.createTableStructure)(doc, columns, rows);
25
+ if (format) {
26
+ table.format = (0, tslib_1.__assign)({}, format);
27
+ }
24
28
  (0, roosterjs_content_model_dom_1.normalizeTable)(table, editor.getPendingFormat() || insertPosition.marker.format);
25
29
  (0, adjustIndentation_1.adjustTableIndentation)(insertPosition, table);
26
30
  // Assign default vertical align
27
- format = format || { verticalAlign: 'top' };
28
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, format);
31
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
32
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, tableMetadataFormat);
29
33
  (0, roosterjs_content_model_dom_1.mergeModel)(model, doc, context, {
30
34
  insertPosition: insertPosition,
31
35
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;AAAA,6EAAiF;AACjF,kFAAiF;AACjF,2EAQqC;AAGrC;;;;;;;;GAQG;AACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;IAErC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;QACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WA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TableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;AAAA,6EAAiF;AACjF,kFAAiF;AACjF,2EAQqC;AAOrC;;;;;;;;GAQG;AACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ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C;gBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC;AAjDD,kCAiDC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, adjustIndentation_1, createTableStructure_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "../../modelApi/common/adjustIndentation", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, tslib_1, adjustIndentation_1, createTableStructure_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTable = void 0;
@@ -8,10 +8,10 @@ define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../
8
8
  * @param columns Number of columns in table, it also controls the default table cell width:
9
9
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
10
10
  * @param rows Number of rows in table
11
- * @param format (Optional) The table format. If not passed, the default format will be applied:
12
- * background color: #FFF; border color: #ABABAB
11
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
12
+ * @param format (Optional) The table format used for style attributes
13
13
  */
14
- function insertTable(editor, columns, rows, format) {
14
+ function insertTable(editor, columns, rows, tableMetadataFormat, format) {
15
15
  editor.focus();
16
16
  editor.formatContentModel(function (model, context) {
17
17
  var _a, _b, _c;
@@ -19,11 +19,14 @@ define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../
19
19
  if (insertPosition) {
20
20
  var doc = (0, roosterjs_content_model_dom_1.createContentModelDocument)();
21
21
  var table = (0, createTableStructure_1.createTableStructure)(doc, columns, rows);
22
+ if (format) {
23
+ table.format = (0, tslib_1.__assign)({}, format);
24
+ }
22
25
  (0, roosterjs_content_model_dom_1.normalizeTable)(table, editor.getPendingFormat() || insertPosition.marker.format);
23
26
  (0, adjustIndentation_1.adjustTableIndentation)(insertPosition, table);
24
27
  // Assign default vertical align
25
- format = format || { verticalAlign: 'top' };
26
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, format);
28
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
29
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, tableMetadataFormat);
27
30
  (0, roosterjs_content_model_dom_1.mergeModel)(model, doc, context, {
28
31
  insertPosition: insertPosition,
29
32
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;IAaA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAA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AAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IA7CD,kCA6CC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js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,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;oBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;oBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IAjDD,kCAiDC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,3 +1,4 @@
1
+ import { __assign } from "tslib";
1
2
  import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';
2
3
  import { createTableStructure } from '../../modelApi/table/createTableStructure';
3
4
  import { createContentModelDocument, createSelectionMarker, applyTableFormat, deleteSelection, mergeModel, normalizeTable, setSelection, } from 'roosterjs-content-model-dom';
@@ -7,10 +8,10 @@ import { createContentModelDocument, createSelectionMarker, applyTableFormat, de
7
8
  * @param columns Number of columns in table, it also controls the default table cell width:
8
9
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
9
10
  * @param rows Number of rows in table
10
- * @param format (Optional) The table format. If not passed, the default format will be applied:
11
- * background color: #FFF; border color: #ABABAB
11
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
12
+ * @param format (Optional) The table format used for style attributes
12
13
  */
13
- export function insertTable(editor, columns, rows, format) {
14
+ export function insertTable(editor, columns, rows, tableMetadataFormat, format) {
14
15
  editor.focus();
15
16
  editor.formatContentModel(function (model, context) {
16
17
  var _a, _b, _c;
@@ -18,11 +19,14 @@ export function insertTable(editor, columns, rows, format) {
18
19
  if (insertPosition) {
19
20
  var doc = createContentModelDocument();
20
21
  var table = createTableStructure(doc, columns, rows);
22
+ if (format) {
23
+ table.format = __assign({}, format);
24
+ }
21
25
  normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);
22
26
  adjustTableIndentation(insertPosition, table);
23
27
  // Assign default vertical align
24
- format = format || { verticalAlign: 'top' };
25
- applyTableFormat(table, format);
28
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
29
+ applyTableFormat(table, tableMetadataFormat);
26
30
  mergeModel(model, doc, context, {
27
31
  insertPosition: insertPosition,
28
32
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,GACf,MAAM,6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C,CAAC;gBACpC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,GACf,MAAM,6BAA6B,CAAC;AAOrC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,mBAAkD,EAClD,MAAgC;IAEhC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;QACX,IAAM,cAAc,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;QAEvE,IAAI,cAAc,EAAE;YAChB,IAAM,GAAG,GAAG,0BAA0B,EAAE,CAAC;YACzC,IAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACvD,IAAI,MAAM,EAAE;gBACR,KAAK,CAAC,MAAM,gBAAQ,MAAM,CAAE,CAAC;aAChC;YAED,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjF,sBAAsB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAE9C,gCAAgC;YAChC,mBAAmB,GAAG,mBAAmB,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YACtE,gBAAgB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;YAC7C,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,cAAc,gBAAA;gBACd,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;gBACtC,IAAM,MAAM,GAAG,qBAAqB,CAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;gBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.41.0",
7
- "roosterjs-content-model-types": "^9.41.0"
6
+ "roosterjs-content-model-dom": "^9.42.0",
7
+ "roosterjs-content-model-types": "^9.42.0"
8
8
  },
9
- "version": "9.41.0",
9
+ "version": "9.42.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",