{"id":13473285,"url":"https://github.com/alidcast/vue-mobiledoc-editor","last_synced_at":"2025-03-26T17:32:28.353Z","repository":{"id":143787003,"uuid":"76875818","full_name":"alidcast/vue-mobiledoc-editor","owner":"alidcast","description":"A lightweight and customizable editor that allows you to embed rich content using Vuejs components.","archived":true,"fork":false,"pushed_at":"2018-03-08T00:45:16.000Z","size":160,"stargazers_count":74,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-05T20:26:10.868Z","etag":null,"topics":["mobiledoc-editor","ui-components","vue","vue-components","wysiwyg-editor"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alidcast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-12-19T15:57:05.000Z","updated_at":"2024-08-05T20:26:10.869Z","dependencies_parsed_at":"2023-06-08T18:30:43.432Z","dependency_job_id":null,"html_url":"https://github.com/alidcast/vue-mobiledoc-editor","commit_stats":null,"previous_names":["alidcastano/vue-mobiledoc-editor"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alidcast%2Fvue-mobiledoc-editor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alidcast%2Fvue-mobiledoc-editor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alidcast%2Fvue-mobiledoc-editor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alidcast%2Fvue-mobiledoc-editor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alidcast","download_url":"https://codeload.github.com/alidcast/vue-mobiledoc-editor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222156661,"owners_count":16940437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mobiledoc-editor","ui-components","vue","vue-components","wysiwyg-editor"],"created_at":"2024-07-31T16:01:02.370Z","updated_at":"2024-10-30T03:32:04.075Z","avatar_url":"https://github.com/alidcast.png","language":"HTML","funding_links":[],"categories":["基于 Vue","For Vue"],"sub_categories":[],"readme":"# Vue Mobiledoc Editor\n\nA Mobiledoc editor written using Vue and [Mobiledoc Kit](https://github.com/bustlelabs/mobiledoc-kit).\n\n### Installation\n\n```\nnpm install vue-mobiledoc-editor\n```\n\nThe `vue-mobiledoc-editor` will install the `mobiledoc-kit` package as a dependency and load its assets.\n\n### Basic Usage\n\nThis package is composed of two main components:\n\n* `MobiledocEditor`\n* `MobiledocButton`\n\nAdditionally, you can use the following addons:\n* `MobiledocToolbar` (component)\n* `compToCard` (factory function)\n\n\nThe most basic usage with an empty editor and a standard toolbar is:\n\n```\n// template\n\u003cEditor\u003e\n  \u003cToolbar /\u003e\n\u003c/Editor\u003e\n\n// script\nimport Mobiledoc, { MobiledocToolbar } from \"vue-mobiledoc-editor\"\n\nexport default {\n  components: {\n    Editor: Mobiledoc.Editor,\n    Toolbar: MobiledocToolbar\n  }\n}\n\n```\n\nYou can check out the live `mobiledoc-kit` [demo](https://bustle.github.io/mobiledoc-kit/demo/) or clone the repo and run `npm run dev` for a more interactive example.\n\nRead on for how to provide custom configurations to each component.\n\n#### Mobiledoc Editor\n\nThe mobiledoc editor is a component that accepts these Mobiledoc-specific props:\n\n* `mobiledoc`, a Mobiledoc to be edited. (*The package also exports an `EMPTY_MOBILEDOC` template that you can use as a default when passing a `mobiledoc` payload to the editor.*)\n\n* `atoms`, an array of available atoms for use by the editor.\n\n* `cards`, an array of available cards for use by the editor. (Jump to the section on Card-based components for details on how to create cards as Vue components.)\n\n* `cardOptions`, an object of additional props to pass to rendered cards.\n\n* `spellcheck`, a boolean. Defaults to true.\n\n* `autofocus`, a boolean. Defaults to true.\n\n* `placeholder`, a string to use as the placeholder text when the mobiledoc is blank.\n\n* `serializeVersion`, a string representing the mobiledoc version to serialize to when firing the `postWasUpdated` action. Defaults to 0.3.0.\n\n* 'enableEditing', a boolean that represents whether the editor is rendered in display or edit mode.\n\nAdditionally, it can emit the following events:\n\n* `willCreateEditor`, a callback that fires when the Mobiledoc editor instance is about to be created. Takes no arguments.\n\n* `didCreateEditor`, a callback that fires once the Mobiledoc editor instance has been created. Will be called with the editor instance and may be used to configure it further.\n\n* `postWasUpdated`, a callback that will fire whenever the underlying document changes. It is called with the serialized mobiledoc.\n\n(*Note: For placeholder and other mobiledoc-related styles to work, you must import/copy mobiledoc-kit's [default CSS](https://github.com/bustle/mobiledoc-kit/blob/master/src/css/mobiledoc-kit.css) file yourself.*)\n\nExample usage:\n\n```\n\u003cMobiledocEditor\n  placeholder=\"Start Writing...\"\n  @postWasUpdated=\"savePost\"\u003e\n\u003c/MobiledocEditor\u003e\n```\n\nThe editor has the following `refs` and `slots` available:\n\n```HTML\n\u003cMobiledocEditor\u003e\n \u003cslot name=\"header\" /\u003e\n \u003cslot /\u003e \u003c!--default --\u003e\n \u003cdiv ref=\"editorPost\"\u003e \u003c!-- The editor's post is rendered here --\u003e\n \u003cslot name=\"footer\" /\u003e\n\u003c/MobiledocEditor\u003e\n```\n\nYou can further manipulate the editor's post element (e.g. for styling) by using `$refs.editorPost`; or you can grab the editor instance directly using the `didCreateEditor` hook.\n\nUsing `provide/inject`, the Editor also provides the `editorVm` to all child components. The `editorVM` has the following data and methods:\n\n* `editor`, a function that returns the Mobiledoc editor instance itself\n\n* `activeSectionTags`, an object with true values for section tag names in the current selection. For example activeSectionTagNames.isH1.\n\n* `activeMarkupTags`, an object with true values for markup tag names in the current selection. For example activeMarkupTagNames.isStrong\n\n* `canEdit`, a function that returns a boolean stating whether editing is currently enabled or disabled.\n\n* `toggleMarkup`, toggles the passed markup tag name in the current selection.\n\n* `toggleSection`, toggles the passed section tag name in the current selection.\n\n* `toggleLink`, toggles the linking of a selection. The user will be prompted for a URL if required.\n\n* `addAtom`, passed an atom `name`, `text`, and `payload`, will add that atom at the cursor position.\n\n* `addCard`, passed a card `name`, `payload`, and `editMode` will add that card at the end of a post and render it in the specified mode initially.\n\n* `toggleEditMode`, updates the `canEdit` state and toggles the edit mode of the mobiledoc editor.\n\nYou can use the `MobiledocEditor.editor` instance itself to take full advantage of the features in the [mobiledoc-kit API documentation](http://bustlelabs.github.io/mobiledoc-kit/demo/docs/).\n\n\n#### Mobiledoc Button\n\nThe `MobiledocButton` is a functional component that delegates the passed `props` to the appropriate button. Because of this, *every button requires* the `type` prop. Any additional props depend on the type of button.\n\nThere are five types of buttons:\n\n* `MarkupButton`, requires a `tag` prop to identify the type of markup to toggle.\n\n* `SectionButton`, requires a `tag` prop to identify the type of section to toggle.\n\n* `LinkButton`, accepts an optional `prompt` prop that you can pass if you wish to provide a custom dialog that the user will shown when prompted input the link.\n\n* `AtomButton`, requires a `name` prop to identify the atom that will be added to the end of the post and accepts an optional `text` and `payload` prop.\n\n* `CardButton`, requires a `name` prop to identify the card that will be added to the end of the post and accepts an optional `payload` and `mode` prop. There are two `mode` options, `edit` or `display`; the default is `display`.\n\nAdditionally, all buttons accept a`label` prop, to set the content of the button when used as a blockless component.\n\nExample usage:\n\n```\n\u003cMobiledocButton label=\"bold\" type=\"markup\" tag=\"strong\" /\u003e\n```\n\n#### Mobiledoc Toolbar\n\nThe component creates a standard toolbar for the mobiledoc editor.\n\nExample usage:\n\n```\n\u003cMobiledocToolbar /\u003e\n```\n\n### Advanced Usage\n\n#### Component Cards\n\nMobiledoc supports \"cards\", blocks of rich content that are embedded into a post.\n\n`vue-mobiledoc-editor` comes with a helper for using your own Vue components as the display and edit modes of a card.\n\nThe card's properties are passed as props to the component. You can use them like this:\n\n```\n// components/cards/example.vue\n\n\u003ctemplate\u003e\n\u003cdiv\u003e\n  \u003ch1\u003e {{ msg }} \u003c/h1\u003e\n\u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nexport default {\n  name='exCard'\n  props: ['env'],\n  data() {\n    return {\n      msg: this.env.isInEditor ? \"You can edit me!\" : \"I'm immutable!\"\n    }\n  }\n}\n\u003c/script\u003e\n\n```\nThen, to use the component as a card, wrap your own component in the `compToCard`\nserializer function, before passing it to the editor as a card option:\n\n```\n// components/editor.js\n\u003ctemplate\u003e\n\u003cdiv\u003e\n  \u003cEditor :cards='cards'\u003e\n    \u003cBtn type=\"card\" name=\"exCard\"\u003e exCard \u003c/Btn\u003e\n  \u003c/Editor\u003e\n\u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nimport Mobiledoc, { compToCard } from \"vue-mobiledoc-editor\"\nimport example from 'components/cards/example.vue'\n\nexport default {\n  data () {\n    cards: [\n      compToCard(example)\n    ],\n    components: {\n      Editor: Mobiledoc.Editor,\n      Btn: Mobiledoc.Button\n    }\n  }\n}\n\u003c/script\u003e\n```\n\nPlease note that your card must have a name to identify it. So if your component does not have a name, you'll need to provide your own to the serializer function: `compToCard(NamelessComponent, 'MyCardName')`.\n\nThe following mobiledoc-specific properties are passed to the component:\n\n- `env`, an object of that holds environment-specific properties\n- `payload`, an object that holds the data payload retrieved from the mobiledoc for this card\n\nFor more details on the API for authoring cards in vanilla JavaScript, as welll as the `env` properties available to the card, see [CARDS.md](https://github.com/bustlelabs/mobiledoc-kit/blob/master/CARDS.md).\n\n#### Creating custom mobiledoc components\n\nTo create components that control the mobiledoc editor, just inject the `editorVm` to child components.\n\nFor example, you can create a button that toggles whether the editor is editable or not:\n\n```\nexport default {\n  inject: ['editorVm']\n  render(h) {\n    const { canEdit, toggleEditMode } = this.editorVm\n    return h(\n      \u003cbutton @click={ () =\u003e toggleEditMode() }\u003e\n        { canEdit ? 'Display' : 'Edit' }\n      \u003c/button\u003e\n    )\n  }\n}\n```\n\n*Note: Mobiledoc components must be nested under the Mobiledoc `Editor`.*\n\n## Development\n\nTo get started:\n\n* `git clone` this repository\n\n* `npm install`\n\n\nRun the development server:\n\nA development server is available under the `/demo` directory. You can check out the demo for an example of basic usage or to interactively test your contribution.\n\n* `npm run dev` from project root\n\n*  Visit your app at `http://localhost:8080`.\n\n\nRun tests:\n\n* `npm run unit`\n\n\nBuild to `dist/`:\n\n* `npm run build`\n\n\n#### Getting Help\n\nIf you'd like to report a bug or request a feature, please [open an issue](https://github.com/studbits/vue-mobiledoc-editor/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falidcast%2Fvue-mobiledoc-editor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falidcast%2Fvue-mobiledoc-editor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falidcast%2Fvue-mobiledoc-editor/lists"}