| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/apache/htdocs/app/node_modules/prosemirror-collab/dist/ |
Upload File : |
{"version":3,"file":"index.js","sources":["../src/collab.js"],"sourcesContent":["import {Plugin, PluginKey, TextSelection} from \"prosemirror-state\"\n\nclass Rebaseable {\n constructor(step, inverted, origin) {\n this.step = step\n this.inverted = inverted\n this.origin = origin\n }\n}\n\n// : ([Rebaseable], [Step], Transform) → [Rebaseable]\n// Undo a given set of steps, apply a set of other steps, and then\n// redo them.\nexport function rebaseSteps(steps, over, transform) {\n for (let i = steps.length - 1; i >= 0; i--) transform.step(steps[i].inverted)\n for (let i = 0; i < over.length; i++) transform.step(over[i])\n let result = []\n for (let i = 0, mapFrom = steps.length; i < steps.length; i++) {\n let mapped = steps[i].step.map(transform.mapping.slice(mapFrom))\n mapFrom--\n if (mapped && !transform.maybeStep(mapped).failed) {\n transform.mapping.setMirror(mapFrom, transform.steps.length - 1)\n result.push(new Rebaseable(mapped, mapped.invert(transform.docs[transform.docs.length - 1]), steps[i].origin))\n }\n }\n return result\n}\n\n// This state field accumulates changes that have to be sent to the\n// central authority in the collaborating group and makes it possible\n// to integrate changes made by peers into our local document. It is\n// defined by the plugin, and will be available as the `collab` field\n// in the resulting editor state.\nclass CollabState {\n constructor(version, unconfirmed) {\n // : number\n // The version number of the last update received from the central\n // authority. Starts at 0 or the value of the `version` property\n // in the option object, for the editor's value when the option\n // was enabled.\n this.version = version\n\n // : [Rebaseable]\n // The local steps that havent been successfully sent to the\n // server yet.\n this.unconfirmed = unconfirmed\n }\n}\n\nfunction unconfirmedFrom(transform) {\n let result = []\n for (let i = 0; i < transform.steps.length; i++)\n result.push(new Rebaseable(transform.steps[i],\n transform.steps[i].invert(transform.docs[i]),\n transform))\n return result\n}\n\nconst collabKey = new PluginKey(\"collab\")\n\n// :: (?Object) → Plugin\n//\n// Creates a plugin that enables the collaborative editing framework\n// for the editor.\n//\n// config::- An optional set of options\n//\n// version:: ?number\n// The starting version number of the collaborative editing.\n// Defaults to 0.\n//\n// clientID:: ?union<number, string>\n// This client's ID, used to distinguish its changes from those of\n// other clients. Defaults to a random 32-bit number.\nexport function collab(config = {}) {\n config = {version: config.version || 0,\n clientID: config.clientID == null ? Math.floor(Math.random() * 0xFFFFFFFF) : config.clientID}\n\n return new Plugin({\n key: collabKey,\n\n state: {\n init: () => new CollabState(config.version, []),\n apply(tr, collab) {\n let newState = tr.getMeta(collabKey)\n if (newState)\n return newState\n if (tr.docChanged)\n return new CollabState(collab.version, collab.unconfirmed.concat(unconfirmedFrom(tr)))\n return collab\n }\n },\n\n config,\n // This is used to notify the history plugin to not merge steps,\n // so that the history can be rebased.\n historyPreserveItems: true\n })\n}\n\n// :: (state: EditorState, steps: [Step], clientIDs: [union<number, string>], options: ?Object) → Transaction\n// Create a transaction that represents a set of new steps received from\n// the authority. Applying this transaction moves the state forward to\n// adjust to the authority's view of the document.\n//\n// options::- Additional options.\n//\n// mapSelectionBackward:: ?boolean\n// When enabled (the default is `false`), if the current selection\n// is a [text selection](#state.TextSelection), its sides are\n// mapped with a negative bias for this transaction, so that\n// content inserted at the cursor ends up after the cursor. Users\n// usually prefer this, but it isn't done by default for reasons\n// of backwards compatibility.\nexport function receiveTransaction(state, steps, clientIDs, options) {\n // Pushes a set of steps (received from the central authority) into\n // the editor state (which should have the collab plugin enabled).\n // Will recognize its own changes, and confirm unconfirmed steps as\n // appropriate. Remaining unconfirmed steps will be rebased over\n // remote steps.\n let collabState = collabKey.getState(state)\n let version = collabState.version + steps.length\n let ourID = collabKey.get(state).spec.config.clientID\n\n // Find out which prefix of the steps originated with us\n let ours = 0\n while (ours < clientIDs.length && clientIDs[ours] == ourID) ++ours\n let unconfirmed = collabState.unconfirmed.slice(ours)\n steps = ours ? steps.slice(ours) : steps\n\n // If all steps originated with us, we're done.\n if (!steps.length)\n return state.tr.setMeta(collabKey, new CollabState(version, unconfirmed))\n\n let nUnconfirmed = unconfirmed.length\n let tr = state.tr\n if (nUnconfirmed) {\n unconfirmed = rebaseSteps(unconfirmed, steps, tr)\n } else {\n for (let i = 0; i < steps.length; i++) tr.step(steps[i])\n unconfirmed = []\n }\n\n let newCollabState = new CollabState(version, unconfirmed)\n if (options && options.mapSelectionBackward && state.selection instanceof TextSelection) {\n tr.setSelection(TextSelection.between(tr.doc.resolve(tr.mapping.map(state.selection.anchor, -1)),\n tr.doc.resolve(tr.mapping.map(state.selection.head, -1)), -1))\n tr.updated &= ~1\n }\n return tr.setMeta(\"rebased\", nUnconfirmed).setMeta(\"addToHistory\", false).setMeta(collabKey, newCollabState)\n}\n\n// :: (state: EditorState) → ?{version: number, steps: [Step], clientID: union<number, string>, origins: [Transaction]}\n// Provides data describing the editor's unconfirmed steps, which need\n// to be sent to the central authority. Returns null when there is\n// nothing to send.\n//\n// `origins` holds the _original_ transactions that produced each\n// steps. This can be useful for looking up time stamps and other\n// metadata for the steps, but note that the steps may have been\n// rebased, whereas the origin transactions are still the old,\n// unchanged objects.\nexport function sendableSteps(state) {\n let collabState = collabKey.getState(state)\n if (collabState.unconfirmed.length == 0) return null\n return {\n version: collabState.version,\n steps: collabState.unconfirmed.map(s => s.step),\n clientID: collabKey.get(state).spec.config.clientID,\n get origins() { return this._origins || (this._origins = collabState.unconfirmed.map(s => s.origin)) }\n }\n}\n\n// :: (EditorState) → number\n// Get the version up to which the collab plugin has synced with the\n// central authority.\nexport function getVersion(state) {\n return collabKey.getState(state).version\n}\n"],"names":["let","i","const","PluginKey","Plugin","TextSelection"],"mappings":";;;;;;AAEA,IAAM,UAAU,GACd,mBAAW,CAAC,IAAI,EAAE,QAAQ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