lakelib 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/lake.d.ts CHANGED
@@ -358,6 +358,19 @@ interface ThreeParts extends TwoParts {
358
358
  }
359
359
  type NodePath = number[];
360
360
 
361
+ interface ActiveItem {
362
+ node: Nodes;
363
+ name: string;
364
+ attributes: KeyValue;
365
+ styles: KeyValue;
366
+ }
367
+ interface SelectionState {
368
+ activeItems: ActiveItem[];
369
+ disabledNameMap?: Map<string, boolean>;
370
+ selectedNameMap?: Map<string, boolean>;
371
+ selectedValuesMap?: Map<string, string[]>;
372
+ }
373
+
361
374
  type TranslationFunctions = {
362
375
  toolbar: {
363
376
  /**
@@ -971,19 +984,6 @@ type TranslationFunctions = {
971
984
  };
972
985
  };
973
986
 
974
- interface ActiveItem {
975
- node: Nodes;
976
- name: string;
977
- attributes: KeyValue;
978
- styles: KeyValue;
979
- }
980
- interface SelectionState {
981
- activeItems: ActiveItem[];
982
- disabledNameMap?: Map<string, boolean>;
983
- selectedNameMap?: Map<string, boolean>;
984
- selectedValuesMap?: Map<string, string[]>;
985
- }
986
-
987
987
  type NativeRange = Range;
988
988
 
989
989
  /**
@@ -1856,6 +1856,10 @@ declare class Editor {
1856
1856
  * Removes focus from the editor.
1857
1857
  */
1858
1858
  blur(): void;
1859
+ /**
1860
+ * Returns the state of the current selection.
1861
+ */
1862
+ getState(): SelectionState;
1859
1863
  /**
1860
1864
  * Sets the specified content to the editor.
1861
1865
  */
package/lib/lake.js CHANGED
@@ -4395,7 +4395,7 @@ class Toolbar {
4395
4395
  for (const item of this.dropdownItemList) {
4396
4396
  let selectedValues = selectedValuesMap.get(item.name);
4397
4397
  if (selectedValues === undefined) {
4398
- selectedValues = item.selectedValues ? item.selectedValues(activeItems) : [];
4398
+ selectedValues = item.selectedValues && activeItems.length > 0 ? item.selectedValues(activeItems) : [];
4399
4399
  }
4400
4400
  const dropdownNode = this.container.find(`div.lake-dropdown[name="${item.name}"]`);
4401
4401
  let isDisabled = disabledNameMap.get(item.name);
@@ -6273,7 +6273,7 @@ function removeBox(range) {
6273
6273
  return box;
6274
6274
  }
6275
6275
 
6276
- var version = "0.3.5";
6276
+ var version = "0.3.7";
6277
6277
 
6278
6278
  // Converts the custom HTML tags to the special tags that can not be parsed by browser.
6279
6279
  function denormalizeValue(value) {
@@ -7724,37 +7724,7 @@ class Editor {
7724
7724
  * Triggers the statechange event when the current selection is changed.
7725
7725
  */
7726
7726
  this.emitStateChangeEvent = debounce(() => {
7727
- const commandNames = this.command.getNames();
7728
- let activeItems = this.selection.getActiveItems();
7729
- if (activeItems.length > 0 && !this.container.contains(activeItems[0].node)) {
7730
- activeItems = [];
7731
- }
7732
- const disabledNameMap = new Map();
7733
- const selectedNameMap = new Map();
7734
- const selectedValuesMap = new Map();
7735
- if (activeItems.length > 0) {
7736
- for (const name of commandNames) {
7737
- const commandItem = this.command.getItem(name);
7738
- if (commandItem.isDisabled && commandItem.isDisabled(activeItems)) {
7739
- disabledNameMap.set(name, true);
7740
- }
7741
- if (commandItem.isSelected && commandItem.isSelected(activeItems)) {
7742
- selectedNameMap.set(name, true);
7743
- }
7744
- if (commandItem.selectedValues) {
7745
- const values = commandItem.selectedValues(activeItems);
7746
- if (values.length > 0) {
7747
- selectedValuesMap.set(name, values);
7748
- }
7749
- }
7750
- }
7751
- }
7752
- const state = {
7753
- activeItems,
7754
- disabledNameMap,
7755
- selectedNameMap,
7756
- selectedValuesMap,
7757
- };
7727
+ const state = this.getState();
7758
7728
  if (isEqual(state, this.state)) {
7759
7729
  return;
7760
7730
  }
@@ -8095,6 +8065,40 @@ class Editor {
8095
8065
  blur() {
8096
8066
  this.container.blur();
8097
8067
  }
8068
+ /**
8069
+ * Returns the state of the current selection.
8070
+ */
8071
+ getState() {
8072
+ const commandNames = this.command.getNames();
8073
+ let activeItems = this.selection.getActiveItems();
8074
+ if (activeItems.length > 0 && !this.container.contains(activeItems[0].node)) {
8075
+ activeItems = [];
8076
+ }
8077
+ const disabledNameMap = new Map();
8078
+ const selectedNameMap = new Map();
8079
+ const selectedValuesMap = new Map();
8080
+ for (const name of commandNames) {
8081
+ const commandItem = this.command.getItem(name);
8082
+ if (commandItem.isDisabled && commandItem.isDisabled(activeItems)) {
8083
+ disabledNameMap.set(name, true);
8084
+ }
8085
+ if (commandItem.isSelected && commandItem.isSelected(activeItems)) {
8086
+ selectedNameMap.set(name, true);
8087
+ }
8088
+ if (activeItems.length > 0 && commandItem.selectedValues) {
8089
+ const values = commandItem.selectedValues(activeItems);
8090
+ if (values.length > 0) {
8091
+ selectedValuesMap.set(name, values);
8092
+ }
8093
+ }
8094
+ }
8095
+ return {
8096
+ activeItems,
8097
+ disabledNameMap,
8098
+ selectedNameMap,
8099
+ selectedValuesMap,
8100
+ };
8101
+ }
8098
8102
  /**
8099
8103
  * Sets the specified content to the editor.
8100
8104
  */
@@ -8140,6 +8144,8 @@ class Editor {
8140
8144
  this.renderBoxes();
8141
8145
  if (this.toolbar) {
8142
8146
  this.toolbar.render(this);
8147
+ const state = this.getState();
8148
+ this.toolbar.updateState(state);
8143
8149
  }
8144
8150
  document.addEventListener('copy', this.copyListener);
8145
8151
  if (!this.readonly) {