visual-space/visual-editor

Sys - Various Fixes, Renamed DocumentM to DeltaDocM, Fixed placeholder, Added emitEvent param to EditorController, Docs improvements, Various bug fixes, Small API changes

Closed this issue · 0 comments

Due to an internal organisational change the repository was not updated in the last 2 months in small increments. These are multiple changes that have been merge in one large commit.

  • Moved DocumentController in EditorController #222
  • Fixed missing placeholder. When generating the doc tree we were no longer reading from the document param. It was bypassed by reading straight form the state store. This param provided the placeholder doc in case the user doc was empty. We had to separate the placeholder document generation logic to a dedicated service PlaceholderService.
  • Renamed DocumentM to DeltaDocM. This change was made to prevent model collisions with apps that use DocumentM internally.
  • Fixed issue with EditorController getters. They were returning the initial stale value instead of the latest value.
  • Added new param emitEvent for controller.update(). It defaults to true which means that by default any change (update) made to the document will fire the callbacks onReplaceText() and onReplaceTextCompleted(). In certain scenarios when the editor is used in a combination with the state store we might want to disable the emission of a new event. If the state store update the document then we want to prevent the callbacks from being fired. That's when we use emitEvent: false. If the editor has been changed by the user via typing then we want to push this change to the state store. Then we prefer to emit events (call callbacks) as per default behaviour.
  • Added new public method getHeadingsByType() on the controller. Useful for listing the headings of the document in a separate index component.
  • More documentation improvements. Added an overview of the "Hierarchy of Code Flow". As a new dev in the codebase you can get quite confused when trying to understand why you can find 3 compose() and 3 replace() methods in the codebase. There's a very solid explanation behind this architecture.
  • Fixed a bug that kept adding a new whitespace each time the document was updated using update(). #255
    It's a silly combination of factors. But in summary:
    • update() calls clear() and compose().
    • clear() produces a document: [{"insert":"\n"}]
    • compose() then comes and adds: [{"insert":"A\n"}]
    • \n + \n = \n\n
    • The result is: [{"insert":"A\n\n"}]
    • Rinse and repeat
  • Renamed replaceText() back to replace(). Technically speaking this is the correct name. It was change some months ago due to poor understanding on our side of the Quill API. We wanted a name that made it simpler to understand what update(), replace(), compose() do. These methods were very poorly documented. However the naming is correct. They are short names mostly because these are public API methods. Now why they are duplicated is explained in the updated documentation.