@worktile/theia 3.0.0-next.2 → 3.0.0-next.5

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 (61) hide show
  1. package/bundles/worktile-theia.umd.js +281 -232
  2. package/bundles/worktile-theia.umd.js.map +1 -1
  3. package/core/utils/combine-plugins.d.ts +2 -0
  4. package/core/utils/get-plugin-by-key.d.ts +2 -0
  5. package/core/utils/index.d.ts +5 -2
  6. package/core/utils/merge-deep-plugins.d.ts +2 -0
  7. package/core/utils/merge-options.d.ts +2 -2
  8. package/core/utils/nested-structure-by-key.d.ts +2 -0
  9. package/core/utils/plugins-by-key.d.ts +2 -0
  10. package/esm2015/core/create-plugin.js +2 -4
  11. package/esm2015/core/utils/combine-plugins.js +10 -0
  12. package/esm2015/core/utils/flatten-deep-plugins.js +2 -20
  13. package/esm2015/core/utils/get-plugin-by-key.js +8 -0
  14. package/esm2015/core/utils/get-plugin.js +3 -3
  15. package/esm2015/core/utils/index.js +6 -3
  16. package/esm2015/core/utils/merge-deep-plugins.js +16 -0
  17. package/esm2015/core/utils/merge-options.js +6 -2
  18. package/esm2015/core/utils/nested-structure-by-key.js +11 -0
  19. package/esm2015/core/utils/plugins-by-key.js +10 -0
  20. package/esm2015/core/with-theia.js +9 -22
  21. package/esm2015/editor.component.js +2 -3
  22. package/esm2015/interfaces/editor.js +1 -1
  23. package/esm2015/interfaces/utility/nested-structure-by-key.js +1 -1
  24. package/esm2015/plugins/autoformat/autoformat.plugin.js +11 -11
  25. package/esm2015/plugins/blockquote/blockquote.editor.js +8 -8
  26. package/esm2015/plugins/code/code.editor.js +3 -3
  27. package/esm2015/plugins/hr/hr.editor.js +2 -2
  28. package/esm2015/plugins/list/list.editor.js +1 -2
  29. package/esm2015/plugins/list/list.plugin.js +3 -3
  30. package/esm2015/plugins/quick-insert/quick-insert.plugin.js +4 -4
  31. package/esm2015/plugins/table/table.plugin.js +3 -3
  32. package/esm2015/plugins/table/transforms/insert-table.js +2 -2
  33. package/esm2015/plugins/todo-item/todo-item.component.js +8 -9
  34. package/esm2015/plugins/todo-item/todo-item.plugin.js +3 -2
  35. package/esm2015/queries/get-insert-elements-path.js +73 -0
  36. package/esm2015/queries/index.js +3 -3
  37. package/esm2015/transforms/index.js +3 -4
  38. package/esm2015/transforms/insert-elements.js +34 -0
  39. package/fesm2015/worktile-theia.js +262 -223
  40. package/fesm2015/worktile-theia.js.map +1 -1
  41. package/interfaces/editor.d.ts +1 -7
  42. package/interfaces/utility/nested-structure-by-key.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/plugins/autoformat/autoformat.plugin.d.ts +5 -1
  45. package/plugins/quick-insert/quick-insert.plugin.d.ts +2 -0
  46. package/plugins/todo-item/todo-item.component.d.ts +1 -0
  47. package/plugins/todo-item/todo-item.plugin.d.ts +4 -1
  48. package/queries/get-insert-elements-path.d.ts +4 -0
  49. package/queries/index.d.ts +2 -2
  50. package/transforms/index.d.ts +2 -3
  51. package/transforms/insert-elements.d.ts +2 -0
  52. package/core/utils/get-plugins-by-key.d.ts +0 -2
  53. package/core/utils/override-plugins-by-key.d.ts +0 -5
  54. package/esm2015/core/utils/get-plugins-by-key.js +0 -8
  55. package/esm2015/core/utils/override-plugins-by-key.js +0 -27
  56. package/esm2015/queries/is-types-in-parent.js +0 -16
  57. package/esm2015/transforms/insert-element-next.js +0 -40
  58. package/esm2015/transforms/insert-element.js +0 -2
  59. package/queries/is-types-in-parent.d.ts +0 -2
  60. package/transforms/insert-element-next.d.ts +0 -2
  61. package/transforms/insert-element.d.ts +0 -3
@@ -19,10 +19,11 @@ import * as i5 from 'ngx-tethys/input';
19
19
  import { ThyInputModule } from 'ngx-tethys/input';
20
20
  import { TheiaConverter } from '@atinc/selene';
21
21
  import * as _lodash from 'lodash';
22
- import { __rest, __awaiter } from 'tslib';
22
+ import { isObject } from 'ngx-tethys/util';
23
23
  import * as i2 from '@angular/cdk/overlay';
24
24
  import { Overlay, OverlayModule } from '@angular/cdk/overlay';
25
25
  import marked from 'marked';
26
+ import { __rest, __awaiter } from 'tslib';
26
27
  import * as i1$2 from 'ngx-tethys/alert';
27
28
  import { ThyAlertModule } from 'ngx-tethys/alert';
28
29
  import { map, takeUntil, take, delay, startWith, distinctUntilChanged, skip, share, filter, mapTo, debounceTime, pairwise } from 'rxjs/operators';
@@ -1072,24 +1073,7 @@ const flattenDeepPlugins = (editor, plugins) => {
1072
1073
  p.options = {};
1073
1074
  if (!p.nestedStructureByKey)
1074
1075
  p.nestedStructureByKey = {};
1075
- // 如果有 key 重复则进行覆盖
1076
- for (const key in p.nestedStructureByKey) {
1077
- if (!editor.nestedStructureByKey[key]) {
1078
- editor.nestedStructureByKey[key] = p.nestedStructureByKey[key];
1079
- }
1080
- }
1081
- if (!editor.pluginsByKey[p.key]) {
1082
- editor.plugins.push(p);
1083
- editor.pluginsByKey[p.key] = p;
1084
- }
1085
- else {
1086
- const index = editor.plugins.indexOf(editor.pluginsByKey[p.key]);
1087
- const mergedPlugin = _.defaultsDeep(p, editor.pluginsByKey[p.key]);
1088
- if (index >= 0) {
1089
- editor.plugins[index] = mergedPlugin;
1090
- }
1091
- editor.pluginsByKey[p.key] = mergedPlugin;
1092
- }
1076
+ editor.plugins.push(p);
1093
1077
  flattenDeepPlugins(editor, p.plugins);
1094
1078
  });
1095
1079
  };
@@ -1099,7 +1083,7 @@ const getPlugins = (editor) => {
1099
1083
  return (_a = editor === null || editor === void 0 ? void 0 : editor.plugins) !== null && _a !== void 0 ? _a : [];
1100
1084
  };
1101
1085
 
1102
- const getPluginsByKey = (editor) => {
1086
+ const getPluginByKey = (editor) => {
1103
1087
  const plugins = {};
1104
1088
  if (editor === null || editor === void 0 ? void 0 : editor.pluginsByKey) {
1105
1089
  return editor.pluginsByKey;
@@ -1107,7 +1091,7 @@ const getPluginsByKey = (editor) => {
1107
1091
  return plugins;
1108
1092
  };
1109
1093
 
1110
- const getPlugin = (editor, key) => getPluginsByKey(editor)[key];
1094
+ const getPlugin = (editor, key) => getPluginByKey(editor)[key];
1111
1095
 
1112
1096
  const getPluginOptions = (editor, key) => { var _a; return (_a = getPlugin(editor, key).options) !== null && _a !== void 0 ? _a : {}; };
1113
1097
 
@@ -1119,35 +1103,169 @@ const mergeOptions = (plugin, override) => {
1119
1103
  newOptions[option] = _.union(options[option], override.options[option]);
1120
1104
  continue;
1121
1105
  }
1122
- newOptions[option] = options[option];
1106
+ if (isObject(options[option])) {
1107
+ newOptions[option] = _.assign(options[option], override.options[option]);
1108
+ }
1109
+ newOptions[option] = override.options[option];
1123
1110
  }
1124
1111
  plugin.options = newOptions;
1125
1112
  return plugin;
1126
1113
  };
1127
1114
 
1128
- /**
1129
- * 将每个 plugin 从 `overrideByKey` 递归深度合并到具有相同 key 的 plugin(plugin > plugin.plugins)。
1130
- */
1131
- const overridePluginsByKey = (plugin, overrideByKey = {}, nested) => {
1132
- if (overrideByKey[plugin.key]) {
1133
- plugin = mergeOptions(plugin, overrideByKey[plugin.key]);
1134
- const _a = overrideByKey[plugin.key], { plugins: pluginOverridesPlugins } = _a, pluginOverrides = __rest(_a, ["plugins"]);
1135
- plugin = _.defaultsDeep(pluginOverrides, plugin);
1136
- if (!nested) {
1137
- pluginOverridesPlugins === null || pluginOverridesPlugins === void 0 ? void 0 : pluginOverridesPlugins.forEach(pOverrides => {
1138
- if (!plugin.plugins)
1139
- plugin.plugins = [];
1140
- const found = plugin.plugins.find(p => p.key === pOverrides.key);
1141
- if (!found)
1142
- plugin.plugins.push(pOverrides);
1115
+ const combinePlugins = (editor) => {
1116
+ // withOverrides
1117
+ editor.plugins.forEach((plugin) => {
1118
+ if (plugin.withOverrides) {
1119
+ editor = plugin.withOverrides(editor, plugin);
1120
+ }
1121
+ });
1122
+ return editor;
1123
+ };
1124
+
1125
+ const mergeDeepPlugins = (editor, _plugins) => {
1126
+ _plugins.forEach(plugin => {
1127
+ if (plugin.overrideByKey) {
1128
+ const newPlugins = _plugins.filter(p => plugin.overrideByKey[p.key]);
1129
+ newPlugins.forEach(p => {
1130
+ if (editor.pluginsByKey[p.key]) {
1131
+ p = mergeOptions(p, plugin.overrideByKey[p.key]);
1132
+ editor.pluginsByKey[p.key] = _.defaultsDeep(p, plugin.overrideByKey[p.key]);
1133
+ }
1143
1134
  });
1144
1135
  }
1136
+ });
1137
+ };
1138
+
1139
+ const nestedStructureByKey = (editor, plugins) => {
1140
+ // 如果有 key 重复则进行覆盖
1141
+ plugins.forEach((p) => {
1142
+ for (const key in p.nestedStructureByKey) {
1143
+ if (!editor.nestedStructureByKey[key]) {
1144
+ editor.nestedStructureByKey[key] = p.nestedStructureByKey[key];
1145
+ }
1146
+ }
1147
+ });
1148
+ };
1149
+
1150
+ const pluginsByKey = (editor, plugins) => {
1151
+ if (!plugins)
1152
+ return;
1153
+ plugins.forEach((p) => {
1154
+ if (!editor.pluginsByKey[p.key]) {
1155
+ editor.pluginsByKey[p.key] = p;
1156
+ }
1157
+ });
1158
+ };
1159
+
1160
+ const withTheia = (editor, plugins = []) => {
1161
+ let e = editor;
1162
+ e.renderElement = (element) => null;
1163
+ e.renderLeaf = (text) => null;
1164
+ e.isContainer = (value) => false;
1165
+ e.extraElementOptions = [];
1166
+ e.disabled = false;
1167
+ e.plugins = [];
1168
+ e.pluginsByKey = {};
1169
+ e.nestedStructureByKey = {};
1170
+ // withOverridesByKey
1171
+ flattenDeepPlugins(e, plugins);
1172
+ // mount pluginsByKey
1173
+ pluginsByKey(e, plugins);
1174
+ // mount nestedStructureByKey
1175
+ nestedStructureByKey(e, e.plugins);
1176
+ // merge plugin to pluginByKey
1177
+ mergeDeepPlugins(e, e.plugins);
1178
+ e = combinePlugins(e);
1179
+ return e;
1180
+ };
1181
+
1182
+ const createPluginFactory = (defaultPlugin) => (override, overrideByKey = {}) => {
1183
+ return defaultPlugin;
1184
+ };
1185
+
1186
+ const toolbarInitialize = (toolbarItems, global = DefaultGlobalToolbarDefinition, inline = DefaultInlineToolbarDefinition, quick = DefaultQuickToolbarDefinition) => {
1187
+ const toolbarDefinition = {
1188
+ global,
1189
+ inline,
1190
+ quick
1191
+ };
1192
+ const toolbarOperations = new Map();
1193
+ toolbarItems.forEach(i => toolbarOperations.set(i.key, i));
1194
+ const toolbarEntity = nextToolbarEntity(toolbarDefinition, toolbarOperations);
1195
+ return {
1196
+ toolbarDefinition,
1197
+ toolbarOperations,
1198
+ toolbarEntity
1199
+ };
1200
+ };
1201
+ const nextToolbarEntity = (toolbarDefinition, toolbarItems) => {
1202
+ const entity = {};
1203
+ for (const defKey in toolbarDefinition) {
1204
+ entity[defKey] = getToolbarItemByKeys(toolbarDefinition[defKey], toolbarItems);
1145
1205
  }
1146
- if (plugin.plugins) {
1147
- plugin.plugins = plugin.plugins.map(p => overridePluginsByKey(p, overrideByKey, true));
1206
+ return entity;
1207
+ };
1208
+ const getToolbarItemByKeys = (keys, toolbarItems) => {
1209
+ const items = [];
1210
+ keys.forEach((key) => {
1211
+ if (key === `split`) {
1212
+ items.push({ key: `split` });
1213
+ return;
1214
+ }
1215
+ const item = toolbarItems.get(key);
1216
+ if (item && item.includes) {
1217
+ items.push(Object.assign(Object.assign({}, item), { includes: getToolbarItemByKeys(item.includes, toolbarItems) }));
1218
+ return;
1219
+ }
1220
+ if (item) {
1221
+ items.push(item);
1222
+ }
1223
+ });
1224
+ return items;
1225
+ };
1226
+ const createToolbar = (editor, toolbar) => {
1227
+ const toolbarItems = editor === null || editor === void 0 ? void 0 : editor.plugins.reduce((prevItems, nextPlugin) => {
1228
+ var _a;
1229
+ prevItems.push(...((_a = nextPlugin === null || nextPlugin === void 0 ? void 0 : nextPlugin.toolbarItems) !== null && _a !== void 0 ? _a : []));
1230
+ return prevItems;
1231
+ }, []);
1232
+ const toolbarOption = toolbarInitialize(toolbarItems, toolbar === null || toolbar === void 0 ? void 0 : toolbar.global, toolbar === null || toolbar === void 0 ? void 0 : toolbar.inline, toolbar === null || toolbar === void 0 ? void 0 : toolbar.quick);
1233
+ const globalToolbarClass = ['the-global-toolbar', getToolbarClass(editor)];
1234
+ const toolbarEntity = toolbarOption.toolbarEntity;
1235
+ return {
1236
+ globalToolbarClass,
1237
+ toolbarEntity
1238
+ };
1239
+ };
1240
+
1241
+ const UNDOING = new WeakMap();
1242
+ const REDOING = new WeakMap();
1243
+ const withTheHistory = (editor) => {
1244
+ const { undo, redo } = editor;
1245
+ editor.undo = () => {
1246
+ UNDOING.set(editor, true);
1247
+ undo();
1248
+ UNDOING.set(editor, false);
1249
+ };
1250
+ editor.redo = () => {
1251
+ REDOING.set(editor, true);
1252
+ redo();
1253
+ REDOING.set(editor, false);
1254
+ };
1255
+ return editor;
1256
+ };
1257
+ const TheHistoryEditor = {
1258
+ isUndoing(editor) {
1259
+ return UNDOING.get(editor);
1260
+ },
1261
+ isRedoing(editor) {
1262
+ return REDOING.get(editor);
1148
1263
  }
1149
- return plugin;
1150
1264
  };
1265
+ const createTheHistoryPlugin = createPluginFactory({
1266
+ key: PluginKeys.theHistory,
1267
+ withOverrides: withTheHistory
1268
+ });
1151
1269
 
1152
1270
  const setMarks = (editor, marks, at) => {
1153
1271
  Transforms.setNodes(editor, marks, {
@@ -1177,8 +1295,6 @@ const clearMarks = (editor) => {
1177
1295
  }
1178
1296
  };
1179
1297
 
1180
- const insertElement = (editor, element) => editor.insertElement(element);
1181
-
1182
1298
  const isAncestor = (node) => Element$1.isElement(node) || Editor.isEditor(node);
1183
1299
 
1184
1300
  const getLastChild$1 = (node, level) => {
@@ -1836,18 +1952,73 @@ const getDirectlyParent = (editor) => {
1836
1952
  return parentEntry;
1837
1953
  };
1838
1954
 
1839
- const isTypesInParent = (editor, types) => {
1840
- if (!Array.isArray(types)) {
1841
- types = [types];
1842
- }
1955
+ const getInsertElementsPath = (editor, allowParentTypes) => {
1843
1956
  const [, anchorPath] = getBlockAbove(editor);
1844
1957
  if (!anchorPath)
1845
1958
  return false;
1846
- const parentEntry = Editor.above(editor, { match: n => types.includes(n.type) });
1959
+ let parentEntry = Editor.above(editor, { match: n => Editor.isBlock(editor, n) && allowParentTypes.includes(n.type) });
1847
1960
  if (!parentEntry)
1848
1961
  return false;
1849
- const [parentNode] = parentEntry;
1850
- return types.includes(parentNode.type);
1962
+ const [, anchorBlockPath] = anchorBlockEntry(editor);
1963
+ let currentNodePath = anchorBlockPath.slice(0, parentEntry[1].length + 1);
1964
+ let illegalParentEntry = null;
1965
+ // 循环获取最外层的不可插入节点
1966
+ while (true) {
1967
+ const _illegalParentEntry = parentEntry &&
1968
+ Editor.above(editor, {
1969
+ mode: 'lowest',
1970
+ at: parentEntry[1],
1971
+ match: (n) => n.type && !allowParentTypes.includes(n.type)
1972
+ });
1973
+ if (_illegalParentEntry) {
1974
+ const childType = editor.nestedStructureByKey[_illegalParentEntry[0].type];
1975
+ if (!childType) {
1976
+ illegalParentEntry = _illegalParentEntry;
1977
+ }
1978
+ if (allowParentTypes.includes(childType)) {
1979
+ const rootKey = findNestedStructureRootType(editor, _illegalParentEntry[0].type, '');
1980
+ parentEntry =
1981
+ parentEntry &&
1982
+ Editor.above(editor, {
1983
+ mode: 'lowest',
1984
+ at: parentEntry[1],
1985
+ match: (n) => n.type && n.type === rootKey
1986
+ });
1987
+ }
1988
+ else {
1989
+ parentEntry = _illegalParentEntry;
1990
+ }
1991
+ }
1992
+ else {
1993
+ break;
1994
+ }
1995
+ }
1996
+ // 获取不可插入节点的根层节点
1997
+ if (illegalParentEntry) {
1998
+ const rootKey = findNestedStructureRootType(editor, illegalParentEntry[0].type, '');
1999
+ if (rootKey && illegalParentEntry[0].type !== rootKey) {
2000
+ illegalParentEntry = Editor.above(editor, {
2001
+ mode: 'lowest',
2002
+ at: parentEntry[1],
2003
+ match: (n) => n.type && n.type === rootKey
2004
+ });
2005
+ }
2006
+ currentNodePath = illegalParentEntry && illegalParentEntry[1];
2007
+ }
2008
+ return currentNodePath && Path.next(currentNodePath);
2009
+ };
2010
+ // 获取具有嵌套关系的根类型
2011
+ const findNestedStructureRootType = (editor, type, rootKey) => {
2012
+ let parentKey = _lodash.findKey(editor.nestedStructureByKey, value => {
2013
+ return value === type;
2014
+ });
2015
+ if (parentKey) {
2016
+ rootKey = parentKey;
2017
+ return findNestedStructureRootType(editor, parentKey, rootKey);
2018
+ }
2019
+ else {
2020
+ return rootKey || type;
2021
+ }
1851
2022
  };
1852
2023
 
1853
2024
  const isContainNestedType = (editor, types) => {
@@ -1925,7 +2096,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
1925
2096
  isBlockCardCursor: isBlockCardCursor,
1926
2097
  isEmptyParagraphByPath: isEmptyParagraphByPath,
1927
2098
  isContainer: isContainer,
1928
- isTypesInParent: isTypesInParent,
2099
+ getInsertElementsPath: getInsertElementsPath,
1929
2100
  isContainNestedType: isContainNestedType,
1930
2101
  anchorBlock: anchorBlock,
1931
2102
  anchorBlockEntry: anchorBlockEntry,
@@ -1936,26 +2107,20 @@ var index$1 = /*#__PURE__*/Object.freeze({
1936
2107
  someNode: someNode
1937
2108
  });
1938
2109
 
1939
- const insertElementNext = (editor, element) => {
2110
+ const insertElements = (editor, element) => {
1940
2111
  var _a;
1941
2112
  if (Range.isExpanded(editor.selection)) {
1942
2113
  Editor.deleteFragment(editor);
1943
2114
  }
1944
2115
  const type = element.type;
1945
2116
  const allowParentTypes = ((_a = getPluginOptions(editor, type)) === null || _a === void 0 ? void 0 : _a.allowParentTypes) || [];
1946
- const isAllowInsert = isTypesInParent(editor, allowParentTypes);
2117
+ const insertNodePath = getInsertElementsPath(editor, allowParentTypes);
1947
2118
  const [anchorBlock, anchorBlockPath] = anchorBlockEntry(editor);
1948
- const isEmpty = Editor.isEmpty(editor, anchorBlock);
1949
- const isContainNested = isContainNestedType(editor, allowParentTypes);
1950
- if (isAllowInsert && isContainNested) {
1951
- const [, containerPath] = Editor.above(editor, {
1952
- match: n => Editor.isBlock(editor, n) && allowParentTypes.includes(n.type),
1953
- at: editor.selection
1954
- });
2119
+ let isEmpty = Editor.isEmpty(editor, anchorBlock);
2120
+ if (insertNodePath) {
1955
2121
  Editor.withoutNormalizing(editor, () => {
1956
- const containerPathFirstPath = anchorBlockPath.slice(0, containerPath.length + 1);
1957
- Transforms.insertNodes(editor, element, { at: Path.next(containerPathFirstPath) });
1958
- Transforms.select(editor, Editor.start(editor, Path.next(containerPathFirstPath)));
2122
+ Transforms.insertNodes(editor, element, { at: insertNodePath });
2123
+ Transforms.select(editor, Editor.start(editor, insertNodePath));
1959
2124
  if (isEmpty) {
1960
2125
  Transforms.removeNodes(editor, { at: anchorBlockPath });
1961
2126
  }
@@ -2157,8 +2322,7 @@ var index = /*#__PURE__*/Object.freeze({
2157
2322
  __proto__: null,
2158
2323
  setMarks: setMarks,
2159
2324
  clearMarks: clearMarks,
2160
- insertElement: insertElement,
2161
- insertElementNext: insertElementNext,
2325
+ insertElements: insertElements,
2162
2326
  insertParagraph: insertParagraph,
2163
2327
  setNode: setNode,
2164
2328
  unwrapNodesByType: unwrapNodesByType,
@@ -2175,129 +2339,6 @@ var index = /*#__PURE__*/Object.freeze({
2175
2339
  handleContinualInsertBreak: handleContinualInsertBreak
2176
2340
  });
2177
2341
 
2178
- const withTheia = (editor, plugins = []) => {
2179
- let e = editor;
2180
- e.renderElement = (element) => null;
2181
- e.renderLeaf = (text) => null;
2182
- e.insertElement = (element) => insertElementNext(e, element);
2183
- e.isContainer = (value) => false;
2184
- e.extraElementOptions = [];
2185
- e.disabled = false;
2186
- e.plugins = [];
2187
- e.pluginsByKey = {};
2188
- e.nestedStructureByKey = {};
2189
- // withOverridesByKey
2190
- flattenDeepPlugins(e, plugins);
2191
- // 如果 plugin.overrideByKey 存在,则把 plugin.overrideByKey 中的所有 key 覆盖到 editor.pluginsByKey 中
2192
- editor.plugins.forEach(plugin => {
2193
- if (plugin.overrideByKey) {
2194
- const newPlugins = editor.plugins.map(p => {
2195
- return overridePluginsByKey(p, plugin.overrideByKey);
2196
- });
2197
- editor.plugins = [];
2198
- editor.pluginsByKey = {};
2199
- // 再次扁平化覆盖
2200
- flattenDeepPlugins(editor, newPlugins);
2201
- }
2202
- });
2203
- // withOverrides
2204
- e.plugins.forEach((plugin) => {
2205
- if (plugin.withOverrides) {
2206
- e = plugin.withOverrides(e, plugin);
2207
- }
2208
- });
2209
- return e;
2210
- };
2211
-
2212
- const createPluginFactory = (defaultPlugin) => (override, overrideByKey = {}) => {
2213
- overrideByKey[defaultPlugin.key] = override;
2214
- return overridePluginsByKey(Object.assign({}, defaultPlugin), overrideByKey);
2215
- };
2216
-
2217
- const toolbarInitialize = (toolbarItems, global = DefaultGlobalToolbarDefinition, inline = DefaultInlineToolbarDefinition, quick = DefaultQuickToolbarDefinition) => {
2218
- const toolbarDefinition = {
2219
- global,
2220
- inline,
2221
- quick
2222
- };
2223
- const toolbarOperations = new Map();
2224
- toolbarItems.forEach(i => toolbarOperations.set(i.key, i));
2225
- const toolbarEntity = nextToolbarEntity(toolbarDefinition, toolbarOperations);
2226
- return {
2227
- toolbarDefinition,
2228
- toolbarOperations,
2229
- toolbarEntity
2230
- };
2231
- };
2232
- const nextToolbarEntity = (toolbarDefinition, toolbarItems) => {
2233
- const entity = {};
2234
- for (const defKey in toolbarDefinition) {
2235
- entity[defKey] = getToolbarItemByKeys(toolbarDefinition[defKey], toolbarItems);
2236
- }
2237
- return entity;
2238
- };
2239
- const getToolbarItemByKeys = (keys, toolbarItems) => {
2240
- const items = [];
2241
- keys.forEach((key) => {
2242
- if (key === `split`) {
2243
- items.push({ key: `split` });
2244
- return;
2245
- }
2246
- const item = toolbarItems.get(key);
2247
- if (item && item.includes) {
2248
- items.push(Object.assign(Object.assign({}, item), { includes: getToolbarItemByKeys(item.includes, toolbarItems) }));
2249
- return;
2250
- }
2251
- if (item) {
2252
- items.push(item);
2253
- }
2254
- });
2255
- return items;
2256
- };
2257
- const createToolbar = (editor, toolbar) => {
2258
- const toolbarItems = editor === null || editor === void 0 ? void 0 : editor.plugins.reduce((prevItems, nextPlugin) => {
2259
- var _a;
2260
- prevItems.push(...((_a = nextPlugin === null || nextPlugin === void 0 ? void 0 : nextPlugin.toolbarItems) !== null && _a !== void 0 ? _a : []));
2261
- return prevItems;
2262
- }, []);
2263
- const toolbarOption = toolbarInitialize(toolbarItems, toolbar === null || toolbar === void 0 ? void 0 : toolbar.global, toolbar === null || toolbar === void 0 ? void 0 : toolbar.inline, toolbar === null || toolbar === void 0 ? void 0 : toolbar.quick);
2264
- const globalToolbarClass = ['the-global-toolbar', getToolbarClass(editor)];
2265
- const toolbarEntity = toolbarOption.toolbarEntity;
2266
- return {
2267
- globalToolbarClass,
2268
- toolbarEntity
2269
- };
2270
- };
2271
-
2272
- const UNDOING = new WeakMap();
2273
- const REDOING = new WeakMap();
2274
- const withTheHistory = (editor) => {
2275
- const { undo, redo } = editor;
2276
- editor.undo = () => {
2277
- UNDOING.set(editor, true);
2278
- undo();
2279
- UNDOING.set(editor, false);
2280
- };
2281
- editor.redo = () => {
2282
- REDOING.set(editor, true);
2283
- redo();
2284
- REDOING.set(editor, false);
2285
- };
2286
- return editor;
2287
- };
2288
- const TheHistoryEditor = {
2289
- isUndoing(editor) {
2290
- return UNDOING.get(editor);
2291
- },
2292
- isRedoing(editor) {
2293
- return REDOING.get(editor);
2294
- }
2295
- };
2296
- const createTheHistoryPlugin = createPluginFactory({
2297
- key: PluginKeys.theHistory,
2298
- withOverrides: withTheHistory
2299
- });
2300
-
2301
2342
  class TheConversionHintComponent {
2302
2343
  constructor() {
2303
2344
  this.duration = 10000;
@@ -3884,7 +3925,6 @@ const ListEditor = {
3884
3925
  }
3885
3926
  // wrap
3886
3927
  ListEditor.buildListItem(editor);
3887
- // Todo: types
3888
3928
  Transforms.wrapNodes(editor, { type, children: [], start: startIndex }, {
3889
3929
  at: editor.selection,
3890
3930
  match: node => Element$1.isElement(node) && node.type === ElementKinds.listItem
@@ -4184,8 +4224,8 @@ const createListPlugin = createPluginFactory({
4184
4224
  }
4185
4225
  ],
4186
4226
  nestedStructureByKey: {
4187
- [ElementKinds.bulletedList]: [ElementKinds.listItem],
4188
- [ElementKinds.numberedList]: [ElementKinds.listItem]
4227
+ [ElementKinds.bulletedList]: ElementKinds.listItem,
4228
+ [ElementKinds.numberedList]: ElementKinds.listItem
4189
4229
  },
4190
4230
  toolbarItems: [
4191
4231
  {
@@ -4219,18 +4259,17 @@ class TheTodoItemComponent extends TheBaseElementComponent {
4219
4259
  var _a;
4220
4260
  return (_a = this.element) === null || _a === void 0 ? void 0 : _a.indent;
4221
4261
  }
4262
+ get editableWithReadonly() {
4263
+ var _a;
4264
+ return (_a = getPluginOptions(this.editor, PluginKeys.checkItem)) === null || _a === void 0 ? void 0 : _a.editableWithReadonly;
4265
+ }
4222
4266
  ngOnInit() {
4223
4267
  super.ngOnInit();
4224
4268
  }
4225
4269
  onCheck(checked) {
4226
- const options = this.ctxService.getTheOptions();
4227
- const noBindReadonly = options.noBindReadonlyPlugins && options.noBindReadonlyPlugins.includes(ElementKinds.checkItem);
4228
- if (!noBindReadonly && this.readonly) {
4270
+ if (this.readonly && !this.editableWithReadonly) {
4229
4271
  return false;
4230
4272
  }
4231
- else {
4232
- setNode(this.editor, { checked }, this.element);
4233
- }
4234
4273
  setNode(this.editor, { checked }, this.element);
4235
4274
  }
4236
4275
  }
@@ -4355,7 +4394,8 @@ const createTodoItemPlugin = createPluginFactory({
4355
4394
  }
4356
4395
  ],
4357
4396
  options: {
4358
- allowParentTypes: [ElementKinds.tableCell, ElementKinds.blockquote]
4397
+ allowParentTypes: [ElementKinds.tableCell, ElementKinds.blockquote],
4398
+ editableWithReadonly: false
4359
4399
  }
4360
4400
  });
4361
4401
 
@@ -4396,7 +4436,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
4396
4436
 
4397
4437
  const HrEditor = {
4398
4438
  insertHr(editor) {
4399
- insertElement(editor, { type: ElementKinds.hr, children: [{ text: '' }] });
4439
+ insertElements(editor, { type: ElementKinds.hr, children: [{ text: '' }] });
4400
4440
  }
4401
4441
  };
4402
4442
 
@@ -4979,7 +5019,7 @@ function insertTable(opts, editor, rows = 3, columns = 3, getCellContent) {
4979
5019
  }
4980
5020
  // Create the table node
4981
5021
  const table = createTable(opts, columns, rows, getCellContent);
4982
- insertElement(editor, table);
5022
+ insertElements(editor, table);
4983
5023
  }
4984
5024
 
4985
5025
  /**
@@ -5826,13 +5866,13 @@ const autoFormatInline = (editor, { type, between, markup, ignoreTrim, format })
5826
5866
 
5827
5867
  const BlockquoteEditor = {
5828
5868
  toggleBlockquote(editor) {
5869
+ var _a;
5829
5870
  const isActive = isBlockActive(editor, ElementKinds.blockquote);
5871
+ const allowParentTypes = ((_a = getPluginOptions(editor, PluginKeys.blockquote)) === null || _a === void 0 ? void 0 : _a.allowParentTypes) || [];
5830
5872
  if (!isActive) {
5831
- const blockquoteElement = {
5832
- type: ElementKinds.blockquote,
5833
- children: [createEmptyParagraph()]
5834
- };
5835
- insertElement(editor, blockquoteElement);
5873
+ Transforms.wrapNodes(editor, { type: ElementKinds.blockquote, children: [] }, {
5874
+ mode: 'lowest'
5875
+ });
5836
5876
  }
5837
5877
  else {
5838
5878
  Transforms.unwrapNodes(editor, { match: n => Element$1.isElement(n) && n.type === ElementKinds.blockquote });
@@ -5917,7 +5957,7 @@ const CodeEditor = {
5917
5957
  language: DEFAULT_LANGUAGE.value,
5918
5958
  children: [{ text: '' }]
5919
5959
  };
5920
- insertElement(editor, codeElement);
5960
+ insertElements(editor, codeElement);
5921
5961
  }
5922
5962
  else {
5923
5963
  const codeElement = {
@@ -5926,7 +5966,7 @@ const CodeEditor = {
5926
5966
  language: DEFAULT_LANGUAGE.value,
5927
5967
  children: [{ text: '' }]
5928
5968
  };
5929
- insertElement(editor, codeElement);
5969
+ insertElements(editor, codeElement);
5930
5970
  }
5931
5971
  }
5932
5972
  };
@@ -6072,10 +6112,9 @@ const defaultAutoFormatRules = [
6072
6112
  }
6073
6113
  ];
6074
6114
 
6075
- const mergAutoFormateRules = (extraAutoFormatRules) => {
6076
- const combinationData = [...defaultAutoFormatRules, ...extraAutoFormatRules];
6115
+ const mergAutoFormateRules = (rules) => {
6077
6116
  const dataInfo = {};
6078
- combinationData.forEach(item => {
6117
+ rules.forEach(item => {
6079
6118
  if (!dataInfo[item.type + item.key]) {
6080
6119
  dataInfo[item.type + item.key] = Object.assign({}, item);
6081
6120
  }
@@ -6087,11 +6126,9 @@ const withAutoFormat = (editor) => {
6087
6126
  const { insertText } = editor;
6088
6127
  editor.insertText = text => {
6089
6128
  var _a, _b;
6090
- let autoFormatRules = defaultAutoFormatRules;
6091
- if ((_a = editor.extraAutoFormatRules) === null || _a === void 0 ? void 0 : _a.length) {
6092
- const extraRules = mergAutoFormateRules(editor.extraAutoFormatRules);
6093
- autoFormatRules = Object.values(extraRules);
6094
- }
6129
+ let autoFormatRules = (_a = getPluginOptions(editor, PluginKeys.autoFormat)) === null || _a === void 0 ? void 0 : _a.autoFormatRules;
6130
+ const extraRules = mergAutoFormateRules(autoFormatRules);
6131
+ autoFormatRules = Object.values(extraRules);
6095
6132
  if (!isCollapsed(editor.selection)) {
6096
6133
  return insertText(text);
6097
6134
  }
@@ -6170,7 +6207,10 @@ const withAutoFormat = (editor) => {
6170
6207
  };
6171
6208
  const createAutoFormatPlugin = createPluginFactory({
6172
6209
  key: PluginKeys.autoFormat,
6173
- withOverrides: withAutoFormat
6210
+ withOverrides: withAutoFormat,
6211
+ options: {
6212
+ autoFormatRules: defaultAutoFormatRules
6213
+ }
6174
6214
  });
6175
6215
 
6176
6216
  const withTransforms = (editor) => {
@@ -11168,8 +11208,8 @@ const createTablePlugin = createPluginFactory({
11168
11208
  key: PluginKeys.table,
11169
11209
  withOverrides: withTable,
11170
11210
  nestedStructureByKey: {
11171
- [ElementKinds.table]: [ElementKinds.tableRow],
11172
- [ElementKinds.tableRow]: [ElementKinds.tableCell]
11211
+ [ElementKinds.table]: ElementKinds.tableRow,
11212
+ [ElementKinds.tableRow]: ElementKinds.tableCell
11173
11213
  },
11174
11214
  toolbarItems: [
11175
11215
  {
@@ -11472,10 +11512,10 @@ const withQuickInsert = (editor) => {
11472
11512
  const { onKeydown, deleteBackward, onChange } = editor;
11473
11513
  let presseingQuickInsertHotkey = false;
11474
11514
  editor.onKeydown = (event) => {
11475
- var _a, _b;
11476
- const hotkey = (_a = getPluginOptions(editor, PluginKeys.quickInsert)) === null || _a === void 0 ? void 0 : _a.hotkey;
11515
+ const options = getPluginOptions(editor, PluginKeys.quickInsert);
11516
+ const { hotkey, allowHotkeyInTypes } = options;
11477
11517
  if (event.key === hotkey) {
11478
- const types = [...(((_b = editor.options) === null || _b === void 0 ? void 0 : _b.allowContainerOperateTypes) || [])];
11518
+ const types = [...(allowHotkeyInTypes || [])];
11479
11519
  const [block] = getBlockAbove(editor);
11480
11520
  if (isPureEmptyParagraph(editor, block) && allowOpenQuickToolbar(editor, types)) {
11481
11521
  presseingQuickInsertHotkey = true;
@@ -13231,13 +13271,12 @@ class TheEditorComponent extends mixinUnsubscribe(MixinBase) {
13231
13271
  super.ngOnDestroy();
13232
13272
  }
13233
13273
  initialize() {
13234
- var _a, _b, _c;
13274
+ var _a, _b;
13235
13275
  const plugins = [...internalPlugins, ...this.thePlugins];
13236
13276
  this.editor = withTheia(withHistory(withAngular(createEditor(), CLIPBOARD_FORMAT_KEY)), plugins);
13237
13277
  this.generateDecorate();
13238
13278
  this.editor.disabled = (_a = this.theOptions) === null || _a === void 0 ? void 0 : _a.disabled;
13239
13279
  this.editor.extraElementOptions = (_b = this.theOptions) === null || _b === void 0 ? void 0 : _b.extraElementOptions;
13240
- this.editor.extraAutoFormatRules = (_c = this.theOptions) === null || _c === void 0 ? void 0 : _c.extraAutoFormatRules;
13241
13280
  this.editor.options = this.theOptions;
13242
13281
  setEditorUUID(this.editor, idCreator());
13243
13282
  this.theContextService.initialize({
@@ -13818,5 +13857,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
13818
13857
  * Generated bundle index. Do not edit.
13819
13858
  */
13820
13859
 
13821
- export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETEBACKWARD_TYPES, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, ColorEditor, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultQuickToolbarDefinition, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HrEditor, IS_MAC, ImageEditor, IndentEditor, Indents, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, PluginKeys, QuickInsertEditor, STANDARD_HEADING_TYPES, TAB_SPACE, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_QUICK_TOOLBAR_REF, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_MODE_PROVIDER, THE_MODE_TOKEN, THE_UPLOAD_SERVICE_TOKEN, TableEditor, TheBaseElementComponent, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheIndentToolbarComponent, TheMode, TheModeConfig, index$1 as TheQueries, TheToolbarBaseItemComponent, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemMode, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, autoFocus, autoScrollViewHandle, coercePixelsFromCssValue, createEmptyParagraph, createPluginFactory, createToolbar, createVerticalAlignPlugin, dataDeserialize, dataSerializing, deleteColorAndBackgroundColorOfText, deleteElementKey, extractFragment, flattenDeepPlugins, getColsTotalWidth, getEditorUUID, getElementClassByPrefix, getElementHeight, getElementWidth, getEndBlock, getPlugin, getPluginOptions, getPlugins, getPluginsByKey, getRowsTotalHeight, getStartBlock, getToolbarClass, headingOptions, htmlToTheia, idCreator, inValidTypes, internalPlugins, isCleanEmptyParagraph, isPureEmptyParagraph, mergeElementOptions, mergeOptions, overridePluginsByKey, plainToTheia, setEditorUUID, useElementStyle, withTheia };
13860
+ export { ALIGN_BLOCK_TYPES, A_TAG_REL_ATTR, AlignEditor, Alignment, BLOCK_DELETEBACKWARD_TYPES, BlockquoteEditor, CLIPBOARD_FORMAT_KEY, CODEMIRROR_PADDING_TOP, CODE_MODES, COMPONENTS, CONTAINER_BLOCKS, CONTROL_KEY, CodeEditor, ColorEditor, DEFAULT_LANGUAGE, DEFAULT_SCROLL_CONTAINER, DefaultElementOptions, DefaultGlobalToolbarDefinition, DefaultInlineToolbarDefinition, DefaultQuickToolbarDefinition, DropdownMode, ELEMENT_UNIQUE_ID, ElementKinds, ErrorCodes, FontSizeTypes, FontSizes, HEADING_TYPES, HeadingEditor, HrEditor, IS_MAC, ImageEditor, IndentEditor, Indents, LINK_DEFAULT_TEXT, LIST_BLOCK_TYPES, LayoutTypes, LinkEditor, ListEditor, MarkEditor, MarkProps, MarkTypes, PICTURE_ACCEPTED_UPLOAD_MIME, PICTURE_ACCEPTED_UPLOAD_SIZE, PLUGIN_COMPONENTS, PluginKeys, QuickInsertEditor, STANDARD_HEADING_TYPES, TAB_SPACE, THE_EDITOR_CONVERSION_HINT_REF, THE_EDITOR_QUICK_TOOLBAR_REF, THE_EDITOR_UUID, THE_INLINE_TOOLBAR_TYPES, THE_MODE_PROVIDER, THE_MODE_TOKEN, THE_UPLOAD_SERVICE_TOKEN, TableEditor, TheBaseElementComponent, TheContextService, TheDataMode, TheDefaultElementComponent, TheEditor, TheEditorComponent, TheEditorModule, TheImageComponent, TheIndentToolbarComponent, TheMode, TheModeConfig, index$1 as TheQueries, TheToolbarBaseItemComponent, TheToolbarComponent, TheToolbarDropdownComponent, TheToolbarGroupComponent, TheToolbarGroupToken, TheToolbarItemComponent, TheToolbarService, index as TheTransforms, TodoItemEditor, ToolbarActionTypes, ToolbarAlignment, ToolbarItemMode, ToolbarItemType, ToolbarMoreGroup, VOID_BLOCK_TYPES, VerticalAlignEditor, VerticalAlignment, ZERO_WIDTH_CHAR, autoFocus, autoScrollViewHandle, coercePixelsFromCssValue, combinePlugins, createEmptyParagraph, createPluginFactory, createToolbar, createVerticalAlignPlugin, dataDeserialize, dataSerializing, deleteColorAndBackgroundColorOfText, deleteElementKey, extractFragment, flattenDeepPlugins, getColsTotalWidth, getEditorUUID, getElementClassByPrefix, getElementHeight, getElementWidth, getEndBlock, getPlugin, getPluginByKey, getPluginOptions, getPlugins, getRowsTotalHeight, getStartBlock, getToolbarClass, headingOptions, htmlToTheia, idCreator, inValidTypes, internalPlugins, isCleanEmptyParagraph, isPureEmptyParagraph, mergeDeepPlugins, mergeElementOptions, mergeOptions, nestedStructureByKey, plainToTheia, pluginsByKey, setEditorUUID, useElementStyle, withTheia };
13822
13861
  //# sourceMappingURL=worktile-theia.js.map