@limetech/lime-elements 37.39.0 → 37.40.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/cjs/limel-dynamic-label_4.cjs.entry.js +3 -1
  3. package/dist/cjs/limel-dynamic-label_4.cjs.entry.js.map +1 -1
  4. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js +127 -81
  5. package/dist/cjs/limel-prosemirror-adapter.cjs.entry.js.map +1 -1
  6. package/dist/collection/components/list/list.js +3 -1
  7. package/dist/collection/components/list/list.js.map +1 -1
  8. package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-commands.js +70 -65
  9. package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-commands.js.map +1 -1
  10. package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-items.js +9 -8
  11. package/dist/collection/components/text-editor/prosemirror-adapter/menu/menu-items.js.map +1 -1
  12. package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js +32 -0
  13. package/dist/collection/components/text-editor/prosemirror-adapter/menu/types.js.map +1 -0
  14. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js +19 -8
  15. package/dist/collection/components/text-editor/prosemirror-adapter/prosemirror-adapter.js.map +1 -1
  16. package/dist/esm/limel-dynamic-label_4.entry.js +3 -1
  17. package/dist/esm/limel-dynamic-label_4.entry.js.map +1 -1
  18. package/dist/esm/limel-prosemirror-adapter.entry.js +127 -81
  19. package/dist/esm/limel-prosemirror-adapter.entry.js.map +1 -1
  20. package/dist/lime-elements/lime-elements.esm.js +1 -1
  21. package/dist/lime-elements/{p-2967d51c.entry.js → p-4dfeeaf0.entry.js} +2 -2
  22. package/dist/lime-elements/{p-2967d51c.entry.js.map → p-4dfeeaf0.entry.js.map} +1 -1
  23. package/dist/lime-elements/{p-fecf1bf1.entry.js → p-e9f943ac.entry.js} +2 -2
  24. package/dist/lime-elements/p-e9f943ac.entry.js.map +1 -0
  25. package/dist/types/components/text-editor/prosemirror-adapter/menu/menu-commands.d.ts +10 -6
  26. package/dist/types/components/text-editor/prosemirror-adapter/menu/menu-items.d.ts +2 -1
  27. package/dist/types/components/text-editor/prosemirror-adapter/prosemirror-adapter.d.ts +2 -0
  28. package/package.json +1 -1
  29. package/dist/lime-elements/p-fecf1bf1.entry.js.map +0 -1
@@ -15911,78 +15911,114 @@ function exampleSetup(options) {
15911
15911
  }));
15912
15912
  }
15913
15913
 
15914
- class MenuCommandFactory {
15915
- constructor(schema) {
15916
- this.markNames = {
15917
- bold: 'strong',
15918
- italic: 'em',
15919
- underline: 'underline',
15920
- blockquote: 'blockquote',
15921
- headerlevel1: 'headerlevel1',
15922
- headerlevel2: 'headerlevel2',
15923
- headerlevel3: 'headerlevel3',
15924
- addorremovelink: 'link',
15925
- numberedlist: 'ordered_list',
15926
- list: 'bullet_list',
15914
+ /**
15915
+ * The `EditorMenuType` type is used to specify the type of menu items that can be added to the editor toolbar.
15916
+ * Each one represents a different type to be used for creating the prosemirror commands relevant to the button.
15917
+ * The values correspond to the types that can be used with the `prosemirror-commands` library.
15918
+ * @beta
15919
+ */
15920
+ const EditorMenuTypes = {
15921
+ Bold: 'strong',
15922
+ Italic: 'em',
15923
+ Blockquote: 'blockquote',
15924
+ HeaderLevel1: 'headerlevel1',
15925
+ HeaderLevel2: 'headerlevel2',
15926
+ HeaderLevel3: 'headerlevel3',
15927
+ Link: 'link',
15928
+ OrderedList: 'ordered_list',
15929
+ BulletList: 'bullet_list',
15930
+ };
15931
+ /**
15932
+ * `LevelMapping` is used to map string identifiers to numerical header levels.
15933
+ * It provides a way to represent different levels of headings in ProseMirror commands.
15934
+ *
15935
+ * The `Heading` identifier is not a valid level and is used to identify the node type.
15936
+ * The numerical values are used for creating ProseMirror commands to set the level of a heading node in the editor.
15937
+ * @beta
15938
+ */
15939
+ const LevelMapping = {
15940
+ Heading: 'heading',
15941
+ one: 1,
15942
+ two: 2,
15943
+ three: 3,
15944
+ };
15945
+
15946
+ const createToggleMarkCommand = (schema, markName, url) => {
15947
+ const markType = schema.marks[markName];
15948
+ if (!markType) {
15949
+ throw new Error(`Mark "${markName}" not found in schema`);
15950
+ }
15951
+ if (markName === EditorMenuTypes.Link && url) {
15952
+ const attrs = {
15953
+ href: url,
15954
+ target: isExternalLink(url) ? '_blank' : null,
15927
15955
  };
15928
- this.schema = schema;
15956
+ return toggleMark(markType, attrs);
15929
15957
  }
15930
- createCommand(mark) {
15931
- if (this.markNames[mark]) {
15932
- mark = this.markNames[mark];
15933
- }
15934
- switch (mark) {
15935
- case 'strong':
15936
- case 'em':
15937
- case 'underline':
15938
- return this.createToggleMarkCommand(mark);
15939
- case 'paragraph':
15940
- return this.createSetNodeTypeCommand(mark);
15941
- case 'headerlevel1':
15942
- case 'headerlevel2':
15943
- case 'headerlevel3':
15944
- return this.createSetNodeTypeCommand('heading', parseInt(mark[mark.length - 1], 10));
15945
- case 'blockquote':
15946
- return this.createWrapInCommand(mark);
15947
- case 'ordered_list':
15948
- case 'bullet_list':
15949
- return this.createListCommand(mark);
15950
- default:
15951
- throw new Error(`The Mark "${mark}" is not supported`);
15952
- }
15958
+ return toggleMark(markType);
15959
+ };
15960
+ const isExternalLink = (url) => {
15961
+ return !url.startsWith(window.location.origin);
15962
+ };
15963
+ const createSetNodeTypeCommand = (schema, nodeType, level) => {
15964
+ const type = schema.nodes[nodeType];
15965
+ if (!type) {
15966
+ throw new Error(`Node type "${nodeType}" not found in schema`);
15953
15967
  }
15954
- createToggleMarkCommand(markName) {
15955
- const markType = this.schema.marks[markName];
15956
- if (!markType) {
15957
- throw new Error(`Mark "${markName}" not found in schema`);
15958
- }
15959
- return toggleMark(markType);
15968
+ if (nodeType === 'heading' && level) {
15969
+ return setBlockType(type, { level: level });
15960
15970
  }
15961
- createSetNodeTypeCommand(nodeType, level) {
15962
- const type = this.schema.nodes[nodeType];
15963
- if (!type) {
15964
- throw new Error(`Node type "${nodeType}" not found in schema`);
15965
- }
15966
- if (nodeType === 'heading' && level) {
15967
- return setBlockType(type, { level: level });
15968
- }
15969
- else {
15970
- return setBlockType(type);
15971
- }
15971
+ else {
15972
+ return setBlockType(type);
15972
15973
  }
15973
- createWrapInCommand(nodeType) {
15974
- const type = this.schema.nodes[nodeType];
15975
- if (!type) {
15976
- throw new Error(`Node type "${nodeType}" not found in schema`);
15977
- }
15978
- return wrapIn(type);
15974
+ };
15975
+ const createWrapInCommand = (schema, nodeType) => {
15976
+ const type = schema.nodes[nodeType];
15977
+ if (!type) {
15978
+ throw new Error(`Node type "${nodeType}" not found in schema`);
15979
15979
  }
15980
- createListCommand(listType) {
15981
- const type = this.schema.nodes[listType];
15982
- if (!type) {
15983
- throw new Error(`List type "${listType}" not found in schema`);
15980
+ return wrapIn(type);
15981
+ };
15982
+ const createListCommand = (schema, listType) => {
15983
+ const type = schema.nodes[listType];
15984
+ if (!type) {
15985
+ throw new Error(`List type "${listType}" not found in schema`);
15986
+ }
15987
+ return wrapInList(type);
15988
+ };
15989
+ const commandMapping = {
15990
+ strong: createToggleMarkCommand,
15991
+ em: createToggleMarkCommand,
15992
+ underline: createToggleMarkCommand,
15993
+ headerlevel1: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.one),
15994
+ headerlevel2: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.two),
15995
+ headerlevel3: (schema) => createSetNodeTypeCommand(schema, LevelMapping.Heading, LevelMapping.three),
15996
+ blockquote: createWrapInCommand,
15997
+ /* eslint-disable camelcase */
15998
+ ordered_list: createListCommand,
15999
+ bullet_list: createListCommand,
16000
+ /* eslint-enable camelcase */
16001
+ link: createToggleMarkCommand,
16002
+ };
16003
+ class MenuCommandFactory {
16004
+ constructor(schema) {
16005
+ this.schema = schema;
16006
+ }
16007
+ getCommand(mark, url) {
16008
+ const commandFunc = commandMapping[mark];
16009
+ if (!commandFunc) {
16010
+ throw new Error(`The Mark "${mark}" is not supported`);
15984
16011
  }
15985
- return wrapInList(type);
16012
+ return commandFunc(this.schema, mark, url);
16013
+ }
16014
+ buildKeymap() {
16015
+ return {
16016
+ 'Mod-B': this.getCommand(EditorMenuTypes.Bold),
16017
+ 'Mod-I': this.getCommand(EditorMenuTypes.Italic),
16018
+ 'Mod-Shift-1': this.getCommand(EditorMenuTypes.HeaderLevel1),
16019
+ 'Mod-Shift-2': this.getCommand(EditorMenuTypes.HeaderLevel2),
16020
+ 'Mod-Shift-3': this.getCommand(EditorMenuTypes.HeaderLevel3),
16021
+ };
15986
16022
  }
15987
16023
  }
15988
16024
 
@@ -15996,14 +16032,14 @@ const getCommandSymbols = () => {
15996
16032
  const { mod, shift } = getCommandSymbols();
15997
16033
  const textEditorMenuItems = [
15998
16034
  {
15999
- value: 'strong',
16035
+ value: EditorMenuTypes.Bold,
16000
16036
  text: 'Bold',
16001
16037
  commandText: `${mod} B`,
16002
16038
  icon: '-lime-text-bold',
16003
16039
  iconOnly: true,
16004
16040
  },
16005
16041
  {
16006
- value: 'em',
16042
+ value: EditorMenuTypes.Italic,
16007
16043
  text: 'Italic',
16008
16044
  commandText: `${mod} I`,
16009
16045
  icon: '-lime-text-italic',
@@ -16011,21 +16047,21 @@ const textEditorMenuItems = [
16011
16047
  },
16012
16048
  { separator: true },
16013
16049
  {
16014
- value: 'headerlevel1',
16050
+ value: EditorMenuTypes.HeaderLevel1,
16015
16051
  text: 'Header Level 1',
16016
16052
  commandText: `${mod} ${shift} 1`,
16017
16053
  icon: '-lime-text-h-heading-1',
16018
16054
  iconOnly: true,
16019
16055
  },
16020
16056
  {
16021
- value: 'headerlevel2',
16057
+ value: EditorMenuTypes.HeaderLevel2,
16022
16058
  text: 'Header Level 2',
16023
16059
  commandText: `${mod} ${shift} 2`,
16024
16060
  icon: '-lime-text-h-heading-2',
16025
16061
  iconOnly: true,
16026
16062
  },
16027
16063
  {
16028
- value: 'headerlevel3',
16064
+ value: EditorMenuTypes.HeaderLevel3,
16029
16065
  text: 'Header Level 3',
16030
16066
  commandText: `${mod} ${shift} 3`,
16031
16067
  icon: '-lime-text-h-heading-3',
@@ -16033,19 +16069,19 @@ const textEditorMenuItems = [
16033
16069
  },
16034
16070
  { separator: true },
16035
16071
  {
16036
- value: 'bullet_list',
16072
+ value: EditorMenuTypes.BulletList,
16037
16073
  text: 'Bullet list',
16038
16074
  icon: '-lime-text-bulleted-list',
16039
16075
  iconOnly: true,
16040
16076
  },
16041
16077
  {
16042
- value: 'ordered_list',
16078
+ value: EditorMenuTypes.OrderedList,
16043
16079
  text: 'Numbered list',
16044
16080
  icon: '-lime-text-ordered-list',
16045
16081
  iconOnly: true,
16046
16082
  },
16047
16083
  {
16048
- value: 'blockquote',
16084
+ value: EditorMenuTypes.Blockquote,
16049
16085
  text: 'Blockquote',
16050
16086
  icon: '-lime-text-blockquote',
16051
16087
  iconOnly: true,
@@ -24718,6 +24754,7 @@ const ProsemirrorAdapter = class {
24718
24754
  constructor(hostRef) {
24719
24755
  index.registerInstance(this, hostRef);
24720
24756
  this.change = index.createEvent(this, "change", 7);
24757
+ this.editorKeyMap = {};
24721
24758
  this.initializeTextEditor = async () => {
24722
24759
  this.actionBarItems = textEditorMenuItems;
24723
24760
  const mySchema = new Schema({
@@ -24732,13 +24769,19 @@ const ProsemirrorAdapter = class {
24732
24769
  await this.contentConverter.parseAsHTML(this.value, schema$1);
24733
24770
  }
24734
24771
  const initialDoc = DOMParser.fromSchema(mySchema).parse(initialContentElement);
24772
+ this.menuCommandFactory = new MenuCommandFactory(mySchema);
24773
+ this.editorKeyMap = this.menuCommandFactory.buildKeymap();
24774
+ const keymapPlugin = keymap(this.editorKeyMap);
24735
24775
  this.view = new EditorView(this.host.shadowRoot.querySelector('#editor'), {
24736
24776
  state: EditorState.create({
24737
24777
  doc: initialDoc,
24738
- plugins: exampleSetup({
24739
- schema: mySchema,
24740
- menuBar: false,
24741
- }),
24778
+ plugins: [
24779
+ ...exampleSetup({
24780
+ schema: mySchema,
24781
+ menuBar: false,
24782
+ }),
24783
+ keymapPlugin,
24784
+ ],
24742
24785
  }),
24743
24786
  dispatchTransaction: (transaction) => {
24744
24787
  const newState = this.view.state.apply(transaction);
@@ -24753,10 +24796,9 @@ const ProsemirrorAdapter = class {
24753
24796
  };
24754
24797
  this.handleActionBarItem = (event) => {
24755
24798
  event.preventDefault();
24756
- const { text } = event.detail;
24757
- const mark = text.replace(/\s/g, '').toLowerCase();
24799
+ const { value } = event.detail;
24758
24800
  try {
24759
- const command = this.menuCommandFactory.createCommand(mark);
24801
+ const command = this.menuCommandFactory.getCommand(value);
24760
24802
  this.executeCommand(command);
24761
24803
  }
24762
24804
  catch (error) {
@@ -24816,7 +24858,11 @@ const ProsemirrorAdapter = class {
24816
24858
  transaction = tr;
24817
24859
  });
24818
24860
  this.view.dispatch(transaction);
24819
- this.view.focus();
24861
+ this.setFocus();
24862
+ }
24863
+ setFocus() {
24864
+ var _a;
24865
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.focus();
24820
24866
  }
24821
24867
  get host() { return index.getElement(this); }
24822
24868
  static get watchers() { return {