@syllepsis/plugin-basic
Advanced tools
@@ -186,6 +186,5 @@ var __extends = (this && this.__extends) || (function () { | ||
| var insertImageInEditor = function (editor, dataInfos, config) { | ||
| var _a, _b, _c; | ||
| var _a; | ||
| var state = editor.view.state; | ||
| var pos = state.selection.from; | ||
| var $pos = state.doc.resolve(pos); | ||
| var imageType = (_a = state.schema.nodes) === null || _a === void 0 ? void 0 : _a.image; | ||
@@ -195,6 +194,2 @@ var images = __spreadArray([], dataInfos, true); | ||
| // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order | ||
| var isInTable = ((_c = (_b = $pos.node(1)) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.name) === 'table' && $pos.depth >= 2; | ||
| if (isInTable) { | ||
| images.reverse(); | ||
| } | ||
| images.forEach(function (_a) { | ||
@@ -206,10 +201,5 @@ var _b, _c; | ||
| var imageAttrs = __assign({ width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth, name: image.getAttribute('name') || '', alt: '', align: ((_c = (_b = imageType === null || imageType === void 0 ? void 0 : imageType.attrs) === null || _b === void 0 ? void 0 : _b.align) === null || _c === void 0 ? void 0 : _c.default) || 'center' }, attrs); | ||
| if (isInTable) { | ||
| editor.insert({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } | ||
| else { | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| }); | ||
| if (insertNodes.content.length && !isInTable) | ||
| if (insertNodes.content.length) | ||
| editor.insert(insertNodes, pos); | ||
@@ -216,0 +206,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/atom/image/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;gBACL,OAAO,EAAE,CAAC;aACX;YACD,MAAM,EAAE;gBACN,OAAO,EAAE,CAAC;aACX;YACD,KAAK,EAAE;gBACL,OAAO,EAAE,QAAiB;aAC3B;SACF,CAAC;QArFA,gBAAgB,CAAC,KAAK,CAAC,aAAa,EAAE,KAAI,CAAC,CAAC;QAC5C,KAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAEnB,IAAM,KAA0B,KAAI,CAAC,KAAK,EAAlC,KAAK,WAAA,EAAE,GAAG,SAAA,EAAK,IAAI,cAArB,gBAAuB,CAAa,CAAC;QAC3C,aAAa;QACb,KAAI,CAAC,KAAK,gBAAQ,IAAI,CAAE,CAAC;QACzB,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,YAAY;YAAE,KAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACvD,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,cAAc;YAAE,KAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;;IACvD,CAAC;IA8EH,YAAC;AAAD,CAAC,AA7FD,CAAoB,SAAS,GA6F5B;AAED;IAA0B,+BAAqB;IAA/C;QAAA,qEAIC;QAHQ,UAAI,GAAG,WAAW,CAAC;QACnB,gBAAU,GAAG,eAAe,CAAC;QAC7B,YAAM,GAAG,KAAK,CAAC;;IACxB,CAAC;IAAD,kBAAC;AAAD,CAAC,AAJD,CAA0B,SAAS,GAIlC;AAED,OAAO,EAAE,KAAK,EAAc,eAAe,EAAE,WAAW,EAAc,CAAC","sourcesContent":["import { BlockAtom, getPx, INodeInfo, SylApi, SylController, SylPlugin } from '@syllepsis/adapter';\nimport { DOMOutputSpecArray, Node, Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nimport {\n addAttrsByConfig,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n isMatchObject,\n isObjectURL,\n setDOMAttrByConfig,\n} from '../../utils';\nimport { ImageAttrs, ImageProps, IUpdateImageProps, TUploadDataType } from './types';\nimport {\n checkDomain,\n constructAttrs,\n correctSize,\n getImageFileList,\n getInputImageFiles,\n transformBlobFromObjectURL,\n} from './utils';\n\nconst PLUGIN_NAME = 'image';\n\nconst BASE_CONFIG: ImageProps = {\n uploader: () => Promise.resolve(''),\n uploadBeforeInsert: false,\n placeholder: '',\n uploadType: 'blob' as const,\n listenDrop: true,\n listenPaste: true,\n maxLength: 20,\n uploadMaxWidth: 375,\n};\n\nconst getMaxWidth = (editor?: SylApi) => {\n let maxWidth = editor?.command.image?.getConfiguration().maxWidth;\n if (maxWidth === undefined && editor) {\n maxWidth = editor.view.dom.scrollWidth - 40;\n }\n return maxWidth;\n};\n// parse the DOM of image which generated by the the ImagePlugin\nconst parseSylDOM = (\n dom: HTMLElement,\n fixClass: string,\n captionClass: string,\n addAttributes?: ImageProps['addAttributes'],\n maxWidth?: number,\n) => {\n const image = dom.querySelector('img');\n if (!image) return false;\n\n const caption = dom.querySelector(captionClass) as HTMLInputElement | HTMLParagraphElement | null;\n const fixer = dom.querySelector(fixClass);\n\n const alt = (caption && (caption.innerText || (caption as HTMLInputElement).value)) || '';\n const src = (image && image.src) || '';\n let width = image.width;\n let height = image.height;\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n let align: ImageAttrs['align'] = dom.getAttribute('align') as ImageAttrs['align'];\n if (!align && fixer) {\n const className = fixer.className;\n if (className.includes('left')) align = 'left';\n else if (className.includes('right')) align = 'right';\n }\n\n const name = image.getAttribute('name') || '';\n const attrs: ImageAttrs = { src, alt, width, height, align, name };\n addAttributes && getFromDOMByConfig(addAttributes, dom, attrs);\n\n return attrs;\n};\n\nconst uploadImg = async (editor: SylApi, src: string, fileName: string, config: ImageProps) => {\n let res: TUploadDataType = src;\n const { uploader, uploadType, onUploadError, deleteFailedUpload } = config;\n if (!uploader) throw new Error('Must provide uploader!');\n if (isObjectURL(src)) res = await transformBlobFromObjectURL(src);\n\n if (typeof res !== 'string' && uploadType === 'file') {\n res = new File([res as Blob], fileName, { type: res?.type });\n }\n try {\n const uploadRes = await uploader(res, {\n src,\n });\n if (typeof uploadRes === 'string') return { src: uploadRes || src };\n return { src, ...uploadRes };\n } catch (err) {\n if (deleteFailedUpload) {\n const nodeInfos = editor.getExistNodes(PLUGIN_NAME);\n nodeInfos.some(({ node, pos }) => {\n if (node.attrs.src === src) {\n editor.delete(pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (onUploadError) onUploadError(res, err);\n else throw err;\n }\n};\n\nconst insertImageInEditor = (\n editor: SylApi,\n dataInfos: { image?: HTMLImageElement; attrs?: { src: string; [key: string]: any } }[],\n config: Partial<ImageProps>,\n) => {\n const { state } = editor.view;\n const pos = state.selection.from;\n const $pos = state.doc.resolve(pos);\n const imageType = state.schema.nodes?.image;\n const images = [...dataInfos];\n const insertNodes = { type: 'doc', content: [] as INodeInfo[] };\n // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order\n const isInTable = $pos.node(1)?.type?.name === 'table' && $pos.depth >= 2;\n if (isInTable) {\n images.reverse();\n }\n images.forEach(({ image, attrs }) => {\n if (!image || !attrs) return;\n const imageAttrs: Partial<ImageAttrs> = {\n width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth,\n name: image.getAttribute('name') || '',\n alt: '',\n align: imageType?.attrs?.align?.default || 'center',\n ...attrs,\n };\n if (isInTable) {\n editor.insert({ type: PLUGIN_NAME, attrs: imageAttrs });\n } else {\n insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs });\n }\n });\n if (insertNodes.content.length && !isInTable) editor.insert(insertNodes, pos);\n};\n\n// get the picture file and judge whether to upload it in advance\nconst insertImageWithFiles = async (editor: SylApi, files: File[], config: Partial<ImageProps>) => {\n const results = await Promise.all(\n files.map(\n f =>\n new Promise(async resolve => {\n if (config.checkBeforeInsert && !(await config.checkBeforeInsert(f))) return resolve({});\n\n const url = window.URL.createObjectURL(f);\n let attrs: undefined | { src: string } = { src: url };\n const image = document.createElement('img');\n\n image.onload = async () => {\n if (config.uploadBeforeInsert) {\n const uploadRes = await uploadImg(editor, url, f.name, config);\n if (!uploadRes) resolve({});\n else attrs = { ...attrs, ...uploadRes };\n }\n resolve({ attrs, image });\n };\n image.onerror = async e => {\n const { onUploadError } = config;\n onUploadError && onUploadError(f, e as Event);\n resolve({});\n };\n\n image.src = attrs.src;\n image.setAttribute('name', f.name);\n }) as Promise<{ image?: HTMLImageElement; attrs?: { src: string } }>,\n ),\n );\n\n insertImageInEditor(editor, results, config);\n};\n\nconst updateImageUrl = async (editor: SylApi, props: IUpdateImageProps, config: ImageProps) => {\n const { src, name } = props.attrs;\n if (props.state === undefined) props.state = {};\n const state = props.state;\n let imageAttrs: Partial<ImageAttrs> = {};\n\n try {\n // upload state, only single upload request is allowed in the same instance at the same time\n if (state.uploading || (!isObjectURL(src) && checkDomain(src, config))) {\n imageAttrs = await correctSize(props.attrs);\n } else {\n state.uploading = true;\n const attrs = await uploadImg(editor, src, name, config);\n state.uploading = false;\n if (!attrs) return;\n imageAttrs = await constructAttrs(props.attrs, attrs);\n }\n const nodePos = props.getPos();\n if (typeof nodePos !== 'number') return;\n const $pos = editor.view.state.doc.resolve(nodePos);\n const curNode = $pos.nodeAfter;\n // confirm the image node exist\n if (!curNode || curNode.type.name !== PLUGIN_NAME || curNode.attrs.src !== src) return;\n if (!isMatchObject({ ...props.attrs, ...imageAttrs }, props.attrs)) {\n editor.delete($pos.pos, 1, { addToHistory: false });\n editor.insertCard(PLUGIN_NAME, { ...props.attrs, ...imageAttrs }, { index: $pos.pos, deleteSelection: false });\n }\n } finally {\n state.uploading = false;\n }\n};\n\nconst createImageFileInput = (editor: SylApi, config: ImageProps) => {\n const input = createFileInput({\n multiple: true,\n accept: config.accept || 'image/*',\n onChange: (e: Event) => {\n const files = getInputImageFiles(e);\n insertImageWithFiles(editor, files, config);\n },\n getContainer: () => editor.root,\n });\n\n return input;\n};\nclass ImageController extends SylController<ImageProps> {\n public fileInput: HTMLInputElement;\n\n public toolbar = {\n className: 'image',\n tooltip: 'image',\n icon: '' as any,\n handler: () => this.fileInput.click(),\n };\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n if (Object.keys(props).length) this.props = { ...BASE_CONFIG, ...props };\n this.fileInput = createImageFileInput(editor, this.props);\n editor.root.appendChild(this.fileInput);\n }\n\n public command = {\n insertImages: (editor: SylApi, files: File[]) => insertImageWithFiles(editor, files, this.props),\n updateImageUrl: (editor: SylApi, props: IUpdateImageProps) => updateImageUrl(editor, props, this.props),\n getConfiguration: () => this.props,\n };\n\n public eventHandler = {\n handleClickOn(\n editor: SylApi,\n view: EditorView,\n pos: number,\n node: ProsemirrorNode,\n nodePos: number,\n event: MouseEvent,\n ) {\n if (node.type.name === PLUGIN_NAME) {\n const caption = (event.target as HTMLElement).closest('input');\n if (caption) {\n if (caption) caption.focus();\n const newTextSelection = TextSelection.create(view.state.doc, nodePos);\n view.dispatch(view.state.tr.setSelection(newTextSelection));\n return true;\n }\n // when the currently selected image is a picture, but the system behaves as a cursor, correct the selection.(real is 'Range')\n const { state, dispatch } = view;\n const curSelection = window.getSelection();\n if (curSelection && curSelection.type === 'Caret') {\n dispatch(state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos)));\n return true;\n }\n return false;\n }\n return false;\n },\n handlePaste: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as ClipboardEvent;\n if ((this.props && !this.props.listenPaste) || !event.clipboardData) {\n return false;\n }\n const files = getImageFileList(event.clipboardData.files);\n const html = event.clipboardData.getData('text/html');\n const text = event.clipboardData.getData('text/plain');\n // if clipBoard get files and without any text and the src of img is a blob, then treat it as file\n if (\n !files.length ||\n text ||\n (html && (html.match(/<img/g)?.length !== 1 || !/<img[^>]*\\s+src=['\"]blob:[^>]*>/.test(html)))\n ) {\n return false;\n }\n editor.command.image!.insertImages(files);\n return true;\n },\n handleDOMEvents: {\n drop: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as DragEvent;\n\n if (view.dragging || (this.props && !this.props.listenDrop) || !event.dataTransfer) {\n return false;\n }\n const files: File[] = getImageFileList(event.dataTransfer.files);\n if (!files.length) return false;\n editor.command.image!.insertImages(files);\n e.preventDefault();\n return true;\n },\n },\n };\n\n public editorWillUnmount = () => {\n this.editor.root.removeChild(this.fileInput);\n };\n}\n\nclass Image extends BlockAtom<ImageAttrs> {\n public props: ImageProps;\n public name = PLUGIN_NAME;\n public traceSelection = false;\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n addAttrsByConfig(props.addAttributes, this);\n this.props = props;\n\n const { align, alt, ...rest } = this.attrs;\n // @ts-ignore\n this.attrs = { ...rest };\n if (!this.props.disableAlign) this.attrs.align = align;\n if (!this.props.disableCaption) this.attrs.alt = alt;\n }\n\n public parseDOM = [\n {\n tag: 'div.syl-image-wrapper',\n getAttrs: (dom: HTMLElement) =>\n parseSylDOM(dom, '.syl-image-fixer', '.syl-image-caption', this.props.addAttributes, getMaxWidth(this.editor)),\n },\n {\n tag: 'img',\n getAttrs: (dom: HTMLImageElement) => {\n if (!dom.src) return false;\n const attrWidth = dom.getAttribute('width');\n const attrHeight = dom.getAttribute('height');\n const maxWidth = getMaxWidth(this.editor);\n\n let width = getPx(dom.style.width || (attrWidth && `${attrWidth}px`) || '', 16);\n let height = getPx(dom.style.height || (attrHeight && `${attrHeight}px`) || '', 16);\n\n if (!width || isNaN(width)) width = 0;\n if (!height || isNaN(height)) height = 0;\n\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n const formattedAttrs = {\n src: dom.getAttribute('src') || '',\n alt: dom.getAttribute('alt') || '',\n name: dom.getAttribute('name') || '',\n align: (dom.getAttribute('align') || undefined) as any,\n width,\n height,\n };\n\n getFromDOMByConfig(this.props.addAttributes, dom, formattedAttrs);\n\n return formattedAttrs;\n },\n },\n ];\n public toDOM = (node: Node) => {\n const { align, width, height, ...attrs } = node.attrs;\n setDOMAttrByConfig(this.props.addAttributes, node, attrs);\n\n if (width) attrs.width = getFixSize(width);\n if (height) attrs.height = getFixSize(height);\n\n const renderSpec = ['img', attrs] as DOMOutputSpecArray;\n if (this.inline) return renderSpec;\n\n const alignAttrs = this.props.disableAlign ? {} : { align: align || 'center' };\n const outputArray = ['div', { class: 'syl-image-wrapper', ...alignAttrs }, renderSpec];\n attrs.alt && outputArray.push(['p', { class: 'syl-image-caption' }, attrs.alt]);\n return (outputArray as unknown) as DOMOutputSpecArray;\n };\n\n public attrs = {\n src: {\n default: '',\n },\n alt: {\n default: '',\n },\n name: {\n default: '',\n },\n width: {\n default: 0,\n },\n height: {\n default: 0,\n },\n align: {\n default: 'center' as const,\n },\n };\n}\n\nclass ImagePlugin extends SylPlugin<ImageProps> {\n public name = PLUGIN_NAME;\n public Controller = ImageController;\n public Schema = Image;\n}\n\nexport { Image, ImageAttrs, ImageController, ImagePlugin, ImageProps };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/atom/image/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAqB,aAAa,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEnG,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGjE,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,GAC3B,MAAM,SAAS,CAAC;AAEjB,IAAM,WAAW,GAAG,OAAO,C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;AAED,OAAO,EAAE,KAAK,EAAc,eAAe,EAAE,WAAW,EAAc,CAAC","sourcesContent":["import { BlockAtom, getPx, INodeInfo, SylApi, SylController, SylPlugin } from '@syllepsis/adapter';\nimport { DOMOutputSpecArray, Node, Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nimport {\n addAttrsByConfig,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n isMatchObject,\n isObjectURL,\n setDOMAttrByConfig,\n} from '../../utils';\nimport { ImageAttrs, ImageProps, IUpdateImageProps, TUploadDataType } from './types';\nimport {\n checkDomain,\n constructAttrs,\n correctSize,\n getImageFileList,\n getInputImageFiles,\n transformBlobFromObjectURL,\n} from './utils';\n\nconst PLUGIN_NAME = 'image';\n\nconst BASE_CONFIG: ImageProps = {\n uploader: () => Promise.resolve(''),\n uploadBeforeInsert: false,\n placeholder: '',\n uploadType: 'blob' as const,\n listenDrop: true,\n listenPaste: true,\n maxLength: 20,\n uploadMaxWidth: 375,\n};\n\nconst getMaxWidth = (editor?: SylApi) => {\n let maxWidth = editor?.command.image?.getConfiguration().maxWidth;\n if (maxWidth === undefined && editor) {\n maxWidth = editor.view.dom.scrollWidth - 40;\n }\n return maxWidth;\n};\n// parse the DOM of image which generated by the the ImagePlugin\nconst parseSylDOM = (\n dom: HTMLElement,\n fixClass: string,\n captionClass: string,\n addAttributes?: ImageProps['addAttributes'],\n maxWidth?: number,\n) => {\n const image = dom.querySelector('img');\n if (!image) return false;\n\n const caption = dom.querySelector(captionClass) as HTMLInputElement | HTMLParagraphElement | null;\n const fixer = dom.querySelector(fixClass);\n\n const alt = (caption && (caption.innerText || (caption as HTMLInputElement).value)) || '';\n const src = (image && image.src) || '';\n let width = image.width;\n let height = image.height;\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n let align: ImageAttrs['align'] = dom.getAttribute('align') as ImageAttrs['align'];\n if (!align && fixer) {\n const className = fixer.className;\n if (className.includes('left')) align = 'left';\n else if (className.includes('right')) align = 'right';\n }\n\n const name = image.getAttribute('name') || '';\n const attrs: ImageAttrs = { src, alt, width, height, align, name };\n addAttributes && getFromDOMByConfig(addAttributes, dom, attrs);\n\n return attrs;\n};\n\nconst uploadImg = async (editor: SylApi, src: string, fileName: string, config: ImageProps) => {\n let res: TUploadDataType = src;\n const { uploader, uploadType, onUploadError, deleteFailedUpload } = config;\n if (!uploader) throw new Error('Must provide uploader!');\n if (isObjectURL(src)) res = await transformBlobFromObjectURL(src);\n\n if (typeof res !== 'string' && uploadType === 'file') {\n res = new File([res as Blob], fileName, { type: res?.type });\n }\n try {\n const uploadRes = await uploader(res, {\n src,\n });\n if (typeof uploadRes === 'string') return { src: uploadRes || src };\n return { src, ...uploadRes };\n } catch (err) {\n if (deleteFailedUpload) {\n const nodeInfos = editor.getExistNodes(PLUGIN_NAME);\n nodeInfos.some(({ node, pos }) => {\n if (node.attrs.src === src) {\n editor.delete(pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (onUploadError) onUploadError(res, err);\n else throw err;\n }\n};\n\nconst insertImageInEditor = (\n editor: SylApi,\n dataInfos: { image?: HTMLImageElement; attrs?: { src: string; [key: string]: any } }[],\n config: Partial<ImageProps>,\n) => {\n const { state } = editor.view;\n const pos = state.selection.from;\n\n const imageType = state.schema.nodes?.image;\n const images = [...dataInfos];\n const insertNodes = { type: 'doc', content: [] as INodeInfo[] };\n // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order\n images.forEach(({ image, attrs }) => {\n if (!image || !attrs) return;\n const imageAttrs: Partial<ImageAttrs> = {\n width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth,\n name: image.getAttribute('name') || '',\n alt: '',\n align: imageType?.attrs?.align?.default || 'center',\n ...attrs,\n };\n insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs });\n });\n if (insertNodes.content.length) editor.insert(insertNodes, pos);\n};\n\n// get the picture file and judge whether to upload it in advance\nconst insertImageWithFiles = async (editor: SylApi, files: File[], config: Partial<ImageProps>) => {\n const results = await Promise.all(\n files.map(\n f =>\n new Promise(async resolve => {\n if (config.checkBeforeInsert && !(await config.checkBeforeInsert(f))) return resolve({});\n\n const url = window.URL.createObjectURL(f);\n let attrs: undefined | { src: string } = { src: url };\n const image = document.createElement('img');\n\n image.onload = async () => {\n if (config.uploadBeforeInsert) {\n const uploadRes = await uploadImg(editor, url, f.name, config);\n if (!uploadRes) resolve({});\n else attrs = { ...attrs, ...uploadRes };\n }\n resolve({ attrs, image });\n };\n image.onerror = async e => {\n const { onUploadError } = config;\n onUploadError && onUploadError(f, e as Event);\n resolve({});\n };\n\n image.src = attrs.src;\n image.setAttribute('name', f.name);\n }) as Promise<{ image?: HTMLImageElement; attrs?: { src: string } }>,\n ),\n );\n\n insertImageInEditor(editor, results, config);\n};\n\nconst updateImageUrl = async (editor: SylApi, props: IUpdateImageProps, config: ImageProps) => {\n const { src, name } = props.attrs;\n if (props.state === undefined) props.state = {};\n const state = props.state;\n let imageAttrs: Partial<ImageAttrs> = {};\n\n try {\n // upload state, only single upload request is allowed in the same instance at the same time\n if (state.uploading || (!isObjectURL(src) && checkDomain(src, config))) {\n imageAttrs = await correctSize(props.attrs);\n } else {\n state.uploading = true;\n const attrs = await uploadImg(editor, src, name, config);\n state.uploading = false;\n if (!attrs) return;\n imageAttrs = await constructAttrs(props.attrs, attrs);\n }\n const nodePos = props.getPos();\n if (typeof nodePos !== 'number') return;\n const $pos = editor.view.state.doc.resolve(nodePos);\n const curNode = $pos.nodeAfter;\n // confirm the image node exist\n if (!curNode || curNode.type.name !== PLUGIN_NAME || curNode.attrs.src !== src) return;\n if (!isMatchObject({ ...props.attrs, ...imageAttrs }, props.attrs)) {\n editor.delete($pos.pos, 1, { addToHistory: false });\n editor.insertCard(PLUGIN_NAME, { ...props.attrs, ...imageAttrs }, { index: $pos.pos, deleteSelection: false });\n }\n } finally {\n state.uploading = false;\n }\n};\n\nconst createImageFileInput = (editor: SylApi, config: ImageProps) => {\n const input = createFileInput({\n multiple: true,\n accept: config.accept || 'image/*',\n onChange: (e: Event) => {\n const files = getInputImageFiles(e);\n insertImageWithFiles(editor, files, config);\n },\n getContainer: () => editor.root,\n });\n\n return input;\n};\nclass ImageController extends SylController<ImageProps> {\n public fileInput: HTMLInputElement;\n\n public toolbar = {\n className: 'image',\n tooltip: 'image',\n icon: '' as any,\n handler: () => this.fileInput.click(),\n };\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n if (Object.keys(props).length) this.props = { ...BASE_CONFIG, ...props };\n this.fileInput = createImageFileInput(editor, this.props);\n editor.root.appendChild(this.fileInput);\n }\n\n public command = {\n insertImages: (editor: SylApi, files: File[]) => insertImageWithFiles(editor, files, this.props),\n updateImageUrl: (editor: SylApi, props: IUpdateImageProps) => updateImageUrl(editor, props, this.props),\n getConfiguration: () => this.props,\n };\n\n public eventHandler = {\n handleClickOn(\n editor: SylApi,\n view: EditorView,\n pos: number,\n node: ProsemirrorNode,\n nodePos: number,\n event: MouseEvent,\n ) {\n if (node.type.name === PLUGIN_NAME) {\n const caption = (event.target as HTMLElement).closest('input');\n if (caption) {\n if (caption) caption.focus();\n const newTextSelection = TextSelection.create(view.state.doc, nodePos);\n view.dispatch(view.state.tr.setSelection(newTextSelection));\n return true;\n }\n // when the currently selected image is a picture, but the system behaves as a cursor, correct the selection.(real is 'Range')\n const { state, dispatch } = view;\n const curSelection = window.getSelection();\n if (curSelection && curSelection.type === 'Caret') {\n dispatch(state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos)));\n return true;\n }\n return false;\n }\n return false;\n },\n handlePaste: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as ClipboardEvent;\n if ((this.props && !this.props.listenPaste) || !event.clipboardData) {\n return false;\n }\n const files = getImageFileList(event.clipboardData.files);\n const html = event.clipboardData.getData('text/html');\n const text = event.clipboardData.getData('text/plain');\n // if clipBoard get files and without any text and the src of img is a blob, then treat it as file\n if (\n !files.length ||\n text ||\n (html && (html.match(/<img/g)?.length !== 1 || !/<img[^>]*\\s+src=['\"]blob:[^>]*>/.test(html)))\n ) {\n return false;\n }\n editor.command.image!.insertImages(files);\n return true;\n },\n handleDOMEvents: {\n drop: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as DragEvent;\n\n if (view.dragging || (this.props && !this.props.listenDrop) || !event.dataTransfer) {\n return false;\n }\n const files: File[] = getImageFileList(event.dataTransfer.files);\n if (!files.length) return false;\n editor.command.image!.insertImages(files);\n e.preventDefault();\n return true;\n },\n },\n };\n\n public editorWillUnmount = () => {\n this.editor.root.removeChild(this.fileInput);\n };\n}\n\nclass Image extends BlockAtom<ImageAttrs> {\n public props: ImageProps;\n public name = PLUGIN_NAME;\n public traceSelection = false;\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n addAttrsByConfig(props.addAttributes, this);\n this.props = props;\n\n const { align, alt, ...rest } = this.attrs;\n // @ts-ignore\n this.attrs = { ...rest };\n if (!this.props.disableAlign) this.attrs.align = align;\n if (!this.props.disableCaption) this.attrs.alt = alt;\n }\n\n public parseDOM = [\n {\n tag: 'div.syl-image-wrapper',\n getAttrs: (dom: HTMLElement) =>\n parseSylDOM(dom, '.syl-image-fixer', '.syl-image-caption', this.props.addAttributes, getMaxWidth(this.editor)),\n },\n {\n tag: 'img',\n getAttrs: (dom: HTMLImageElement) => {\n if (!dom.src) return false;\n const attrWidth = dom.getAttribute('width');\n const attrHeight = dom.getAttribute('height');\n const maxWidth = getMaxWidth(this.editor);\n\n let width = getPx(dom.style.width || (attrWidth && `${attrWidth}px`) || '', 16);\n let height = getPx(dom.style.height || (attrHeight && `${attrHeight}px`) || '', 16);\n\n if (!width || isNaN(width)) width = 0;\n if (!height || isNaN(height)) height = 0;\n\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n const formattedAttrs = {\n src: dom.getAttribute('src') || '',\n alt: dom.getAttribute('alt') || '',\n name: dom.getAttribute('name') || '',\n align: (dom.getAttribute('align') || undefined) as any,\n width,\n height,\n };\n\n getFromDOMByConfig(this.props.addAttributes, dom, formattedAttrs);\n\n return formattedAttrs;\n },\n },\n ];\n public toDOM = (node: Node) => {\n const { align, width, height, ...attrs } = node.attrs;\n setDOMAttrByConfig(this.props.addAttributes, node, attrs);\n\n if (width) attrs.width = getFixSize(width);\n if (height) attrs.height = getFixSize(height);\n\n const renderSpec = ['img', attrs] as DOMOutputSpecArray;\n if (this.inline) return renderSpec;\n\n const alignAttrs = this.props.disableAlign ? {} : { align: align || 'center' };\n const outputArray = ['div', { class: 'syl-image-wrapper', ...alignAttrs }, renderSpec];\n attrs.alt && outputArray.push(['p', { class: 'syl-image-caption' }, attrs.alt]);\n return (outputArray as unknown) as DOMOutputSpecArray;\n };\n\n public attrs = {\n src: {\n default: '',\n },\n alt: {\n default: '',\n },\n name: {\n default: '',\n },\n width: {\n default: 0,\n },\n height: {\n default: 0,\n },\n align: {\n default: 'center' as const,\n },\n };\n}\n\nclass ImagePlugin extends SylPlugin<ImageProps> {\n public name = PLUGIN_NAME;\n public Controller = ImageController;\n public Schema = Image;\n}\n\nexport { Image, ImageAttrs, ImageController, ImagePlugin, ImageProps };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignCenterPlugin extends SylPlugin { | ||
| declare class AlignCenterPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignCenterController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-center/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAU5C;IAAoC,yCAAe;IAAnD;QAAA,qEAEC;QADQ,WAAK,GAAG,QAAiB,CAAC;;IACnC,CAAC;IAAD,4BAAC;AAAD,CAAC,AAFD,CAAoC,eAAe,GAElD;AAED;IAAgC,qCAAS;IAAzC;QAAA,qEAGC;QAFQ,UAAI,GAAG,cAAc,CAAC;QACtB,gBAAU,GAAG,qBAAqB,CAAC;;IAC5C,CAAC;IAAD,wBAAC;AAAD,CAAC,AAHD,CAAgC,SAAS,GAGxC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_center?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignCenterController extends AlignController {\n public value = 'center' as const;\n}\n\nclass AlignCenterPlugin extends SylPlugin {\n public name = 'align_center';\n public Controller = AlignCenterController;\n}\n\nexport { AlignCenterPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-center/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAUzD;IAAoC,yCAAe;IAAnD;QAAA,qEAEC;QADQ,WAAK,GAAG,QAAiB,CAAC;;IACnC,CAAC;IAAD,4BAAC;AAAD,CAAC,AAFD,CAAoC,eAAe,GAElD;AAED;IAAgC,qCAAsB;IAAtD;QAAA,qEAGC;QAFQ,UAAI,GAAG,cAAc,CAAC;QACtB,gBAAU,GAAG,qBAAqB,CAAC;;IAC5C,CAAC;IAAD,wBAAC;AAAD,CAAC,AAHD,CAAgC,SAAS,GAGxC;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_center?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignCenterController extends AlignController {\n public value = 'center' as const;\n}\n\nclass AlignCenterPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_center';\n public Controller = AlignCenterController;\n}\n\nexport { AlignCenterPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignJustifyPlugin extends SylPlugin { | ||
| declare class AlignJustifyPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignJustifyController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-justify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAU5C;IAAqC,0CAAe;IAApD;QAAA,qEAEC;QADQ,WAAK,GAAG,SAAkB,CAAC;;IACpC,CAAC;IAAD,6BAAC;AAAD,CAAC,AAFD,CAAqC,eAAe,GAEnD;AAED;IAAiC,sCAAS;IAA1C;QAAA,qEAGC;QAFQ,UAAI,GAAG,eAAe,CAAC;QACvB,gBAAU,GAAG,sBAAsB,CAAC;;IAC7C,CAAC;IAAD,yBAAC;AAAD,CAAC,AAHD,CAAiC,SAAS,GAGzC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_justify?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignJustifyController extends AlignController {\n public value = 'justify' as const;\n}\n\nclass AlignJustifyPlugin extends SylPlugin {\n public name = 'align_justify';\n public Controller = AlignJustifyController;\n}\n\nexport { AlignJustifyPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-justify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAUzD;IAAqC,0CAAe;IAApD;QAAA,qEAEC;QADQ,WAAK,GAAG,SAAkB,CAAC;;IACpC,CAAC;IAAD,6BAAC;AAAD,CAAC,AAFD,CAAqC,eAAe,GAEnD;AAED;IAAiC,sCAAsB;IAAvD;QAAA,qEAGC;QAFQ,UAAI,GAAG,eAAe,CAAC;QACvB,gBAAU,GAAG,sBAAsB,CAAC;;IAC7C,CAAC;IAAD,yBAAC;AAAD,CAAC,AAHD,CAAiC,SAAS,GAGzC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_justify?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignJustifyController extends AlignController {\n public value = 'justify' as const;\n}\n\nclass AlignJustifyPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_justify';\n public Controller = AlignJustifyController;\n}\n\nexport { AlignJustifyPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignLeftPlugin extends SylPlugin { | ||
| declare class AlignLeftPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignLeftController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-left/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAS5C;IAAkC,uCAAe;IAAjD;QAAA,qEAEC;QADQ,iBAAW,GAAG,KAAK,CAAC;;IAC7B,CAAC;IAAD,0BAAC;AAAD,CAAC,AAFD,CAAkC,eAAe,GAEhD;AAED;IAA8B,mCAAS;IAAvC;QAAA,qEAGC;QAFQ,UAAI,GAAG,YAAY,CAAC;QACpB,gBAAU,GAAG,mBAAmB,CAAC;;IAC1C,CAAC;IAAD,sBAAC;AAAD,CAAC,AAHD,CAA8B,SAAS,GAGtC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_left?: {\n setStyle: () => void;\n };\n }\n}\nclass AlignLeftController extends AlignController {\n public checkActive = false;\n}\n\nclass AlignLeftPlugin extends SylPlugin {\n public name = 'align_left';\n public Controller = AlignLeftController;\n}\n\nexport { AlignLeftPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-left/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AASzD;IAAkC,uCAAe;IAAjD;QAAA,qEAEC;QADQ,iBAAW,GAAG,KAAK,CAAC;;IAC7B,CAAC;IAAD,0BAAC;AAAD,CAAC,AAFD,CAAkC,eAAe,GAEhD;AAED;IAA8B,mCAAsB;IAApD;QAAA,qEAGC;QAFQ,UAAI,GAAG,YAAY,CAAC;QACpB,gBAAU,GAAG,mBAAmB,CAAC;;IAC1C,CAAC;IAAD,sBAAC;AAAD,CAAC,AAHD,CAA8B,SAAS,GAGtC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_left?: {\n setStyle: () => void;\n };\n }\n}\nclass AlignLeftController extends AlignController {\n public checkActive = false;\n}\n\nclass AlignLeftPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_left';\n public Controller = AlignLeftController;\n}\n\nexport { AlignLeftPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignRightPlugin extends SylPlugin { | ||
| declare class AlignRightPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignRightController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-right/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAU5C;IAAmC,wCAAe;IAAlD;QAAA,qEAEC;QADQ,WAAK,GAAG,OAAgB,CAAC;;IAClC,CAAC;IAAD,2BAAC;AAAD,CAAC,AAFD,CAAmC,eAAe,GAEjD;AAED;IAA+B,oCAAS;IAAxC;QAAA,qEAGC;QAFQ,UAAI,GAAG,aAAa,CAAC;QACrB,gBAAU,GAAG,oBAAoB,CAAC;;IAC3C,CAAC;IAAD,uBAAC;AAAD,CAAC,AAHD,CAA+B,SAAS,GAGvC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_right?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignRightController extends AlignController {\n public value = 'right' as const;\n}\n\nclass AlignRightPlugin extends SylPlugin {\n public name = 'align_right';\n public Controller = AlignRightController;\n}\n\nexport { AlignRightPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-right/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAe,MAAM,WAAW,CAAC;AAUzD;IAAmC,wCAAe;IAAlD;QAAA,qEAEC;QADQ,WAAK,GAAG,OAAgB,CAAC;;IAClC,CAAC;IAAD,2BAAC;AAAD,CAAC,AAFD,CAAmC,eAAe,GAEjD;AAED;IAA+B,oCAAsB;IAArD;QAAA,qEAGC;QAFQ,UAAI,GAAG,aAAa,CAAC;QACrB,gBAAU,GAAG,oBAAoB,CAAC;;IAC3C,CAAC;IAAD,uBAAC;AAAD,CAAC,AAHD,CAA+B,SAAS,GAGvC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_right?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignRightController extends AlignController {\n public value = 'right' as const;\n}\n\nclass AlignRightPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_right';\n public Controller = AlignRightController;\n}\n\nexport { AlignRightPlugin };\n"]} |
| import { SylApi, SylController } from '@syllepsis/adapter'; | ||
| declare class AlignController extends SylController { | ||
| interface IAlignProps { | ||
| /** includes all related nodes not just the top child node that supports `align` attributes */ | ||
| inclusive?: boolean; | ||
| } | ||
| declare class AlignController extends SylController<IAlignProps> { | ||
| checkActive: boolean; | ||
@@ -14,2 +18,2 @@ value: 'left' | 'right' | 'center' | 'justify'; | ||
| } | ||
| export { AlignController }; | ||
| export { AlignController, IAlignProps }; |
@@ -26,11 +26,13 @@ var __extends = (this && this.__extends) || (function () { | ||
| _this.toolbar = { | ||
| handler: function (editor) { return _this.command.setStyle(editor); } | ||
| handler: function (editor) { return _this.command.setStyle(editor); }, | ||
| }; | ||
| _this.command = { | ||
| setStyle: function (editor) { | ||
| setAlign(editor.view, _this.value); | ||
| setAlign(editor.view, _this.value, _this.props.inclusive); | ||
| editor.focus(); | ||
| } | ||
| }, | ||
| }; | ||
| _this.disable = function (editor) { return !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align'); }; | ||
| _this.disable = function (editor) { | ||
| return !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align'); | ||
| }; | ||
| _this.active = function () { return (_this.checkActive ? checkParentHaveAttr(_this.editor.view, 'align', _this.value) : false); }; | ||
@@ -37,0 +39,0 @@ return _this; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/extension/common/align/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,OAAO,EAAU,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEvF;IAA8B,mCAAa;IAA3C;QAAA,qEAiBC;QAhBQ,iBAAW,GAAG,IAAI,CAAC;QACnB,WAAK,GAA4C,MAAM,CAAC;QAExD,aAAO,GAAG;YACf,OAAO,EAAE,UAAC,MAAc,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAA7B,CAA6B;SAC3D,CAAC;QAEK,aAAO,GAAG;YACf,QAAQ,EAAE,UAAC,MAAc;gBACvB,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC;gBAClC,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;SACF,CAAC;QAEK,aAAO,GAAG,UAAC,MAAc,IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,YAAY,YAAY,CAAC,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAvG,CAAuG,CAAC;QACtI,YAAM,GAAG,cAAM,OAAA,CAAC,KAAI,CAAC,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAvF,CAAuF,CAAC;;IAChH,CAAC;IAAD,sBAAC;AAAD,CAAC,AAjBD,CAA8B,aAAa,GAiB1C;AAED,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { SylApi, SylController } from '@syllepsis/adapter';\nimport { AllSelection } from 'prosemirror-state';\n\nimport { checkParentHaveAttr, checkParentSupportAttr, setAlign } from '../../../utils';\n\nclass AlignController extends SylController {\n public checkActive = true;\n public value: 'left' | 'right' | 'center' | 'justify' = 'left';\n\n public toolbar = {\n handler: (editor: SylApi) => this.command.setStyle(editor)\n };\n\n public command = {\n setStyle: (editor: SylApi) => {\n setAlign(editor.view, this.value);\n editor.focus();\n }\n };\n\n public disable = (editor: SylApi) => !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align');\n public active = () => (this.checkActive ? checkParentHaveAttr(this.editor.view, 'align', this.value) : false);\n}\n\nexport { AlignController };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/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llepsis/adapter';\nimport { AllSelection } from 'prosemirror-state';\n\nimport { checkParentHaveAttr, checkParentSupportAttr, setAlign } from '../../../utils';\n\ninterface IAlignProps {\n /** includes all related nodes not just the top child node that supports `align` attributes */\n inclusive?: boolean;\n}\n\nclass AlignController extends SylController<IAlignProps> {\n public checkActive = true;\n public value: 'left' | 'right' | 'center' | 'justify' = 'left';\n\n public toolbar = {\n handler: (editor: SylApi) => this.command.setStyle(editor),\n };\n\n public command = {\n setStyle: (editor: SylApi) => {\n setAlign(editor.view, this.value, this.props.inclusive);\n editor.focus();\n },\n };\n\n public disable = (editor: SylApi) =>\n !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align');\n public active = () => (this.checkActive ? checkParentHaveAttr(this.editor.view, 'align', this.value) : false);\n}\n\nexport { AlignController, IAlignProps };\n"]} |
@@ -7,3 +7,3 @@ import { SylApi, Types } from '@syllepsis/adapter'; | ||
| declare const checkParentSupportAttr: (view: EditorView, attrName: string) => boolean; | ||
| declare const setAlign: (view: EditorView, align: 'left' | 'center' | 'right' | 'justify') => boolean; | ||
| declare const setAlign: (view: EditorView, align: 'left' | 'center' | 'right' | 'justify', inclusive?: boolean) => boolean; | ||
| declare const checkParentHaveAttr: (view: EditorView, attrName: string, attrVal: string) => boolean; | ||
@@ -36,2 +36,2 @@ declare type IUserAttrsConfig = Types.StringMap<{ | ||
| }) => Promise<void>; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, IUserAttrsConfig, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler }; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, IUserAttrsConfig, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler, }; |
@@ -85,3 +85,4 @@ var __assign = (this && this.__assign) || function () { | ||
| }; | ||
| var setAlign = function (view, align) { | ||
| var setAlign = function (view, align, inclusive) { | ||
| if (inclusive === void 0) { inclusive = false; } | ||
| var state = view.state, dispatch = view.dispatch; | ||
@@ -96,5 +97,5 @@ var tr = state.tr; | ||
| state.doc.nodesBetween(from, to, function (node, nodePos) { | ||
| if (node.isTextblock || node.attrs.align !== undefined) { | ||
| if (node.attrs.align !== undefined) { | ||
| tr.setNodeMarkup(nodePos, undefined, __assign(__assign({}, node.attrs), { align: align })); | ||
| return false; | ||
| return inclusive; | ||
| } | ||
@@ -222,3 +223,3 @@ }); | ||
| }); }; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler }; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler, }; | ||
| //# sourceMappingURL=tools.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/utils/tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,IAAM,cAAc,GAAG,UAAC,YAAgC,EAAE,QAAgB;IACxE,IAAI,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,YAAY,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,IAAM,gBAAgB,GAAG,U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AK,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAY,EAAE,KAAK,CAAC,CAAC;iBAC5D;gBACD,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;;;;KACjC,CAAC;AAGF,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EAEb,gBAAgB,EAChB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,EACpB,CAAC","sourcesContent":["import { SylApi, Types } from '@syllepsis/adapter';\nimport { Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nconst getMarkDisable = (excludeMarks: string | undefined, markName: string) => {\n if (!excludeMarks) return false;\n if (excludeMarks === '_') return true;\n if (excludeMarks.split(/\\s/).includes(markName)) return true;\n return false;\n};\n\nconst checkMarkDisable = (view: EditorView, markName: string) => {\n const { $from } = view.state.selection;\n if ($from.parent.type.spec.code) return true;\n const excludeMarks = $from.parent.type.spec.excludeMarks;\n if (!getMarkDisable(excludeMarks, markName)) {\n if ($from.depth > 1) {\n const parentExcludeMarks = $from.node($from.depth - 1).type.spec.excludeMarks;\n return getMarkDisable(parentExcludeMarks, markName);\n }\n return false;\n }\n\n return true;\n};\n\nconst checkSupportAttr = (node: ProsemirrorNode, attrName: string) => node.attrs[attrName] !== undefined;\n\nconst checkParentSupportAttr = (view: EditorView, attrName: string) => {\n const { selection } = view.state;\n if (selection instanceof NodeSelection) {\n return checkSupportAttr(selection.node, attrName);\n }\n const { $from, $to } = selection;\n let isSupport = checkSupportAttr(selection.$from.node(), attrName);\n if (!isSupport && $from.nodeAfter && $from.pos === $to.pos) {\n isSupport = checkSupportAttr($from.nodeAfter, attrName);\n }\n return isSupport;\n};\n\nconst setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify') => {\n const { state, dispatch } = view;\n const tr = state.tr;\n const { ranges } = state.selection;\n if (!ranges.length) return false;\n ranges.forEach(range => {\n const from = range.$from.pos;\n const to = range.$to.pos;\n state.doc.nodesBetween(from, to, (node, nodePos) => {\n if (node.isTextblock || node.attrs.align !== undefined) {\n tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, align });\n return false;\n }\n });\n });\n dispatch(tr);\n return true;\n};\n\nconst checkParentHaveAttr = (view: EditorView, attrName: string, attrVal: string) =>\n view.state.selection.$from.parent.attrs[attrName] === attrVal;\n\ntype IUserAttrsConfig = Types.StringMap<{\n // used to extend default attrs\n default: any;\n [key: string]: any;\n getFromDOM: (dom: HTMLElement) => any | void | undefined; // used in `parseDOM`\n setDOMAttr: (value: string, attrs: Types.StringMap<any>) => void; // used in `toDOM`\n}>;\n\n// add user configuration to attrs attribute\nconst addAttrsByConfig = (config: IUserAttrsConfig = {}, schema: Types.StringMap<any>) => {\n if (!schema.attrs) schema.attrs = {};\n Object.keys(config).forEach(name => {\n Object.keys(config[name]).forEach(spec => {\n if (spec === 'getFromDOM' || spec === 'setDOMAttr') return;\n if (!schema.attrs[name]) schema.attrs[name] = {};\n schema.attrs[name][spec] = config[name][spec];\n });\n });\n};\n\n// uses the default value when return undefined\nconst getFromDOMByConfig = (config: IUserAttrsConfig = {}, dom: HTMLElement, parseAttrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => {\n const value = config[name].getFromDOM(dom);\n if (value !== undefined) Object.assign(parseAttrs, { [name]: value });\n });\n\n// used to construct dom in `toDOM`\nconst setDOMAttrByConfig = (config: IUserAttrsConfig = {}, node: ProsemirrorNode, attrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => config[name].setDOMAttr(node.attrs[name], attrs));\n\n// Keep the decimal point\nconst getFixSize = (num: number, count = 3) => Number(num.toFixed(count).replace(/\\.?0+$/, ''));\n\nconst createFileInput = ({\n multiple = false,\n accept,\n onChange,\n getContainer = () => document.body,\n}: {\n multiple: boolean;\n accept: string;\n onChange: (e: Event) => void;\n getContainer: () => HTMLElement;\n}) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.multiple = multiple;\n input.accept = accept;\n input.style.display = 'none';\n input.addEventListener('change', e => {\n onChange(e);\n (e.target as HTMLInputElement).value = '';\n });\n getContainer().appendChild(input);\n return input;\n};\n\nconst isMatchObject = (objStatic: any, objCompare: any) => {\n if (objStatic === objCompare) return true;\n if (!(objStatic && typeof objStatic === 'object') || !(objCompare && typeof objCompare === 'object')) return false;\n const isArray = Array.isArray(objStatic);\n if (Array.isArray(objCompare) !== isArray) return false;\n if (isArray) {\n if (objStatic.length !== objCompare.length) return false;\n for (let i = 0; i < objStatic.length; i++) if (!isMatchObject(objStatic[i], objCompare[i])) return false;\n } else {\n for (const p in objStatic) if (!(p in objCompare) || !isMatchObject(objStatic[p], objCompare[p])) return false;\n }\n return true;\n};\n\nconst keymapToggleMark = (name: string) => (editor: SylApi) => {\n const isActive = editor.isActive(name);\n editor.setFormat({ [name]: !isActive });\n return true;\n};\n\nconst simpleUploadHandler = async (config: {\n name: string;\n target: HTMLInputElement;\n uploader: (file: File, editor: SylApi) => Promise<any>;\n uploadBeforeInsert: boolean;\n editor: SylApi;\n getAttrs: (url: string, file: File) => Record<string, any>;\n}) => {\n const { name, target, uploader, getAttrs, uploadBeforeInsert, editor } = config;\n if (!target.files || !target.files.length) return;\n const file = target.files[0];\n let index = editor.getSelection().index;\n let url = '';\n if (!uploadBeforeInsert) {\n url = URL.createObjectURL(file);\n editor.insertCard(name, getAttrs(url, file), index);\n }\n const attrs = await uploader(file, editor);\n if (!uploadBeforeInsert) {\n index = -1;\n editor.getExistNodes(name).some(val => {\n if (val.node.attrs.src === url) {\n index = val.pos;\n editor.delete(val.pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (attrs && index > -1) {\n index > -1 && editor.insertCard(name, attrs as any, index);\n }\n url && URL.revokeObjectURL(url);\n};\n\n\nexport {\n addAttrsByConfig,\n checkMarkDisable,\n checkParentHaveAttr,\n checkParentSupportAttr,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n getMarkDisable,\n isMatchObject,\n IUserAttrsConfig,\n keymapToggleMark,\n setAlign,\n setDOMAttrByConfig,\n simpleUploadHandler\n};\n"]} | ||
| {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/utils/tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,IAAM,cAAc,GAAG,UAAC,YAAgC,EAAE,QAAgB;IACxE,IAAI,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,YAAY,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,IAAM,gBAAgB,GAAG,UAAC,IAAgB,EAAE,QAAgB;IAClD,IAAA,KAAK,GAAK,IAAI,CAAC,KAAK,CAAC,SAAS,MAAzB,CAA0B;IACvC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;IACzD,IAAI,CAAC,cAAc,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE;QAC3C,IAAI,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE;YACnB,IAAM,kBAAkB,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;YAC9E,OAAO,cAAc,CAAC,kBAAkB,EAAE,QA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,CAAC;oBAChC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;iBACrD;gBACa,qBAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,EAAA;;gBAApC,KAAK,GAAG,SAA4B;gBAC1C,IAAI,CAAC,kBAAkB,EAAE;oBACvB,KAAK,GAAG,CAAC,CAAC,CAAC;oBACX,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG;wBACjC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;4BAC9B,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;4BAChB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;4BACnD,OAAO,IAAI,CAAC;yBACb;oBACH,CAAC,CAAC,CAAC;iBACJ;gBACD,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACvB,KAAK,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAY,EAAE,KAAK,CAAC,CAAC;iBAC5D;gBACD,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;;;;KACjC,CAAC;AAEF,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,cAAc,EACd,aAAa,EAEb,gBAAgB,EAChB,QAAQ,EACR,kBAAkB,EAClB,mBAAmB,GACpB,CAAC","sourcesContent":["import { SylApi, Types } from '@syllepsis/adapter';\nimport { Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nconst getMarkDisable = (excludeMarks: string | undefined, markName: string) => {\n if (!excludeMarks) return false;\n if (excludeMarks === '_') return true;\n if (excludeMarks.split(/\\s/).includes(markName)) return true;\n return false;\n};\n\nconst checkMarkDisable = (view: EditorView, markName: string) => {\n const { $from } = view.state.selection;\n if ($from.parent.type.spec.code) return true;\n const excludeMarks = $from.parent.type.spec.excludeMarks;\n if (!getMarkDisable(excludeMarks, markName)) {\n if ($from.depth > 1) {\n const parentExcludeMarks = $from.node($from.depth - 1).type.spec.excludeMarks;\n return getMarkDisable(parentExcludeMarks, markName);\n }\n return false;\n }\n\n return true;\n};\n\nconst checkSupportAttr = (node: ProsemirrorNode, attrName: string) => node.attrs[attrName] !== undefined;\n\nconst checkParentSupportAttr = (view: EditorView, attrName: string) => {\n const { selection } = view.state;\n if (selection instanceof NodeSelection) {\n return checkSupportAttr(selection.node, attrName);\n }\n const { $from, $to } = selection;\n let isSupport = checkSupportAttr(selection.$from.node(), attrName);\n if (!isSupport && $from.nodeAfter && $from.pos === $to.pos) {\n isSupport = checkSupportAttr($from.nodeAfter, attrName);\n }\n return isSupport;\n};\n\nconst setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify', inclusive = false) => {\n const { state, dispatch } = view;\n const tr = state.tr;\n const { ranges } = state.selection;\n if (!ranges.length) return false;\n ranges.forEach(range => {\n const from = range.$from.pos;\n const to = range.$to.pos;\n state.doc.nodesBetween(from, to, (node, nodePos) => {\n if (node.attrs.align !== undefined) {\n tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, align });\n return inclusive;\n }\n });\n });\n dispatch(tr);\n return true;\n};\n\nconst checkParentHaveAttr = (view: EditorView, attrName: string, attrVal: string) =>\n view.state.selection.$from.parent.attrs[attrName] === attrVal;\n\ntype IUserAttrsConfig = Types.StringMap<{\n // used to extend default attrs\n default: any;\n [key: string]: any;\n getFromDOM: (dom: HTMLElement) => any | void | undefined; // used in `parseDOM`\n setDOMAttr: (value: string, attrs: Types.StringMap<any>) => void; // used in `toDOM`\n}>;\n\n// add user configuration to attrs attribute\nconst addAttrsByConfig = (config: IUserAttrsConfig = {}, schema: Types.StringMap<any>) => {\n if (!schema.attrs) schema.attrs = {};\n Object.keys(config).forEach(name => {\n Object.keys(config[name]).forEach(spec => {\n if (spec === 'getFromDOM' || spec === 'setDOMAttr') return;\n if (!schema.attrs[name]) schema.attrs[name] = {};\n schema.attrs[name][spec] = config[name][spec];\n });\n });\n};\n\n// uses the default value when return undefined\nconst getFromDOMByConfig = (config: IUserAttrsConfig = {}, dom: HTMLElement, parseAttrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => {\n const value = config[name].getFromDOM(dom);\n if (value !== undefined) Object.assign(parseAttrs, { [name]: value });\n });\n\n// used to construct dom in `toDOM`\nconst setDOMAttrByConfig = (config: IUserAttrsConfig = {}, node: ProsemirrorNode, attrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => config[name].setDOMAttr(node.attrs[name], attrs));\n\n// Keep the decimal point\nconst getFixSize = (num: number, count = 3) => Number(num.toFixed(count).replace(/\\.?0+$/, ''));\n\nconst createFileInput = ({\n multiple = false,\n accept,\n onChange,\n getContainer = () => document.body,\n}: {\n multiple: boolean;\n accept: string;\n onChange: (e: Event) => void;\n getContainer: () => HTMLElement;\n}) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.multiple = multiple;\n input.accept = accept;\n input.style.display = 'none';\n input.addEventListener('change', e => {\n onChange(e);\n (e.target as HTMLInputElement).value = '';\n });\n getContainer().appendChild(input);\n return input;\n};\n\nconst isMatchObject = (objStatic: any, objCompare: any) => {\n if (objStatic === objCompare) return true;\n if (!(objStatic && typeof objStatic === 'object') || !(objCompare && typeof objCompare === 'object')) return false;\n const isArray = Array.isArray(objStatic);\n if (Array.isArray(objCompare) !== isArray) return false;\n if (isArray) {\n if (objStatic.length !== objCompare.length) return false;\n for (let i = 0; i < objStatic.length; i++) if (!isMatchObject(objStatic[i], objCompare[i])) return false;\n } else {\n for (const p in objStatic) if (!(p in objCompare) || !isMatchObject(objStatic[p], objCompare[p])) return false;\n }\n return true;\n};\n\nconst keymapToggleMark = (name: string) => (editor: SylApi) => {\n const isActive = editor.isActive(name);\n editor.setFormat({ [name]: !isActive });\n return true;\n};\n\nconst simpleUploadHandler = async (config: {\n name: string;\n target: HTMLInputElement;\n uploader: (file: File, editor: SylApi) => Promise<any>;\n uploadBeforeInsert: boolean;\n editor: SylApi;\n getAttrs: (url: string, file: File) => Record<string, any>;\n}) => {\n const { name, target, uploader, getAttrs, uploadBeforeInsert, editor } = config;\n if (!target.files || !target.files.length) return;\n const file = target.files[0];\n let index = editor.getSelection().index;\n let url = '';\n if (!uploadBeforeInsert) {\n url = URL.createObjectURL(file);\n editor.insertCard(name, getAttrs(url, file), index);\n }\n const attrs = await uploader(file, editor);\n if (!uploadBeforeInsert) {\n index = -1;\n editor.getExistNodes(name).some(val => {\n if (val.node.attrs.src === url) {\n index = val.pos;\n editor.delete(val.pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (attrs && index > -1) {\n index > -1 && editor.insertCard(name, attrs as any, index);\n }\n url && URL.revokeObjectURL(url);\n};\n\nexport {\n addAttrsByConfig,\n checkMarkDisable,\n checkParentHaveAttr,\n checkParentSupportAttr,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n getMarkDisable,\n isMatchObject,\n IUserAttrsConfig,\n keymapToggleMark,\n setAlign,\n setDOMAttrByConfig,\n simpleUploadHandler,\n};\n"]} |
@@ -189,6 +189,5 @@ "use strict"; | ||
| var insertImageInEditor = function (editor, dataInfos, config) { | ||
| var _a, _b, _c; | ||
| var _a; | ||
| var state = editor.view.state; | ||
| var pos = state.selection.from; | ||
| var $pos = state.doc.resolve(pos); | ||
| var imageType = (_a = state.schema.nodes) === null || _a === void 0 ? void 0 : _a.image; | ||
@@ -198,6 +197,2 @@ var images = __spreadArray([], dataInfos, true); | ||
| // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order | ||
| var isInTable = ((_c = (_b = $pos.node(1)) === null || _b === void 0 ? void 0 : _b.type) === null || _c === void 0 ? void 0 : _c.name) === 'table' && $pos.depth >= 2; | ||
| if (isInTable) { | ||
| images.reverse(); | ||
| } | ||
| images.forEach(function (_a) { | ||
@@ -209,10 +204,5 @@ var _b, _c; | ||
| var imageAttrs = __assign({ width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth, name: image.getAttribute('name') || '', alt: '', align: ((_c = (_b = imageType === null || imageType === void 0 ? void 0 : imageType.attrs) === null || _b === void 0 ? void 0 : _b.align) === null || _c === void 0 ? void 0 : _c.default) || 'center' }, attrs); | ||
| if (isInTable) { | ||
| editor.insert({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } | ||
| else { | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| }); | ||
| if (insertNodes.content.length && !isInTable) | ||
| if (insertNodes.content.length) | ||
| editor.insert(insertNodes, pos); | ||
@@ -219,0 +209,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/atom/image/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAmG;AAEnG,uDAAiE;AAGjE,qCAQqB;AAErB,iCAOiB;AAEjB,IAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,IAAM,WAAW,GAAe;IAC9B,QAAQ,EAAE,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAnB,CAAmB;IACnC,kBAAkB,EAAE,KAAK;IACzB,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,MAAe;IAC3B,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,EAAE;IACb,cAAc,EAAE,GA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;YAAE,KAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;;IACvD,CAAC;IA8EH,YAAC;AAAD,CAAC,AA7FD,CAAoB,mBAAS,GA6F5B;AAQQ,sBAAK;AANd;IAA0B,+BAAqB;IAA/C;QAAA,qEAIC;QAHQ,UAAI,GAAG,WAAW,CAAC;QACnB,gBAAU,GAAG,eAAe,CAAC;QAC7B,YAAM,GAAG,KAAK,CAAC;;IACxB,CAAC;IAAD,kBAAC;AAAD,CAAC,AAJD,CAA0B,mBAAS,GAIlC;AAE4C,kCAAW","sourcesContent":["import { BlockAtom, getPx, INodeInfo, SylApi, SylController, SylPlugin } from '@syllepsis/adapter';\nimport { DOMOutputSpecArray, Node, Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nimport {\n addAttrsByConfig,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n isMatchObject,\n isObjectURL,\n setDOMAttrByConfig,\n} from '../../utils';\nimport { ImageAttrs, ImageProps, IUpdateImageProps, TUploadDataType } from './types';\nimport {\n checkDomain,\n constructAttrs,\n correctSize,\n getImageFileList,\n getInputImageFiles,\n transformBlobFromObjectURL,\n} from './utils';\n\nconst PLUGIN_NAME = 'image';\n\nconst BASE_CONFIG: ImageProps = {\n uploader: () => Promise.resolve(''),\n uploadBeforeInsert: false,\n placeholder: '',\n uploadType: 'blob' as const,\n listenDrop: true,\n listenPaste: true,\n maxLength: 20,\n uploadMaxWidth: 375,\n};\n\nconst getMaxWidth = (editor?: SylApi) => {\n let maxWidth = editor?.command.image?.getConfiguration().maxWidth;\n if (maxWidth === undefined && editor) {\n maxWidth = editor.view.dom.scrollWidth - 40;\n }\n return maxWidth;\n};\n// parse the DOM of image which generated by the the ImagePlugin\nconst parseSylDOM = (\n dom: HTMLElement,\n fixClass: string,\n captionClass: string,\n addAttributes?: ImageProps['addAttributes'],\n maxWidth?: number,\n) => {\n const image = dom.querySelector('img');\n if (!image) return false;\n\n const caption = dom.querySelector(captionClass) as HTMLInputElement | HTMLParagraphElement | null;\n const fixer = dom.querySelector(fixClass);\n\n const alt = (caption && (caption.innerText || (caption as HTMLInputElement).value)) || '';\n const src = (image && image.src) || '';\n let width = image.width;\n let height = image.height;\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n let align: ImageAttrs['align'] = dom.getAttribute('align') as ImageAttrs['align'];\n if (!align && fixer) {\n const className = fixer.className;\n if (className.includes('left')) align = 'left';\n else if (className.includes('right')) align = 'right';\n }\n\n const name = image.getAttribute('name') || '';\n const attrs: ImageAttrs = { src, alt, width, height, align, name };\n addAttributes && getFromDOMByConfig(addAttributes, dom, attrs);\n\n return attrs;\n};\n\nconst uploadImg = async (editor: SylApi, src: string, fileName: string, config: ImageProps) => {\n let res: TUploadDataType = src;\n const { uploader, uploadType, onUploadError, deleteFailedUpload } = config;\n if (!uploader) throw new Error('Must provide uploader!');\n if (isObjectURL(src)) res = await transformBlobFromObjectURL(src);\n\n if (typeof res !== 'string' && uploadType === 'file') {\n res = new File([res as Blob], fileName, { type: res?.type });\n }\n try {\n const uploadRes = await uploader(res, {\n src,\n });\n if (typeof uploadRes === 'string') return { src: uploadRes || src };\n return { src, ...uploadRes };\n } catch (err) {\n if (deleteFailedUpload) {\n const nodeInfos = editor.getExistNodes(PLUGIN_NAME);\n nodeInfos.some(({ node, pos }) => {\n if (node.attrs.src === src) {\n editor.delete(pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (onUploadError) onUploadError(res, err);\n else throw err;\n }\n};\n\nconst insertImageInEditor = (\n editor: SylApi,\n dataInfos: { image?: HTMLImageElement; attrs?: { src: string; [key: string]: any } }[],\n config: Partial<ImageProps>,\n) => {\n const { state } = editor.view;\n const pos = state.selection.from;\n const $pos = state.doc.resolve(pos);\n const imageType = state.schema.nodes?.image;\n const images = [...dataInfos];\n const insertNodes = { type: 'doc', content: [] as INodeInfo[] };\n // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order\n const isInTable = $pos.node(1)?.type?.name === 'table' && $pos.depth >= 2;\n if (isInTable) {\n images.reverse();\n }\n images.forEach(({ image, attrs }) => {\n if (!image || !attrs) return;\n const imageAttrs: Partial<ImageAttrs> = {\n width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth,\n name: image.getAttribute('name') || '',\n alt: '',\n align: imageType?.attrs?.align?.default || 'center',\n ...attrs,\n };\n if (isInTable) {\n editor.insert({ type: PLUGIN_NAME, attrs: imageAttrs });\n } else {\n insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs });\n }\n });\n if (insertNodes.content.length && !isInTable) editor.insert(insertNodes, pos);\n};\n\n// get the picture file and judge whether to upload it in advance\nconst insertImageWithFiles = async (editor: SylApi, files: File[], config: Partial<ImageProps>) => {\n const results = await Promise.all(\n files.map(\n f =>\n new Promise(async resolve => {\n if (config.checkBeforeInsert && !(await config.checkBeforeInsert(f))) return resolve({});\n\n const url = window.URL.createObjectURL(f);\n let attrs: undefined | { src: string } = { src: url };\n const image = document.createElement('img');\n\n image.onload = async () => {\n if (config.uploadBeforeInsert) {\n const uploadRes = await uploadImg(editor, url, f.name, config);\n if (!uploadRes) resolve({});\n else attrs = { ...attrs, ...uploadRes };\n }\n resolve({ attrs, image });\n };\n image.onerror = async e => {\n const { onUploadError } = config;\n onUploadError && onUploadError(f, e as Event);\n resolve({});\n };\n\n image.src = attrs.src;\n image.setAttribute('name', f.name);\n }) as Promise<{ image?: HTMLImageElement; attrs?: { src: string } }>,\n ),\n );\n\n insertImageInEditor(editor, results, config);\n};\n\nconst updateImageUrl = async (editor: SylApi, props: IUpdateImageProps, config: ImageProps) => {\n const { src, name } = props.attrs;\n if (props.state === undefined) props.state = {};\n const state = props.state;\n let imageAttrs: Partial<ImageAttrs> = {};\n\n try {\n // upload state, only single upload request is allowed in the same instance at the same time\n if (state.uploading || (!isObjectURL(src) && checkDomain(src, config))) {\n imageAttrs = await correctSize(props.attrs);\n } else {\n state.uploading = true;\n const attrs = await uploadImg(editor, src, name, config);\n state.uploading = false;\n if (!attrs) return;\n imageAttrs = await constructAttrs(props.attrs, attrs);\n }\n const nodePos = props.getPos();\n if (typeof nodePos !== 'number') return;\n const $pos = editor.view.state.doc.resolve(nodePos);\n const curNode = $pos.nodeAfter;\n // confirm the image node exist\n if (!curNode || curNode.type.name !== PLUGIN_NAME || curNode.attrs.src !== src) return;\n if (!isMatchObject({ ...props.attrs, ...imageAttrs }, props.attrs)) {\n editor.delete($pos.pos, 1, { addToHistory: false });\n editor.insertCard(PLUGIN_NAME, { ...props.attrs, ...imageAttrs }, { index: $pos.pos, deleteSelection: false });\n }\n } finally {\n state.uploading = false;\n }\n};\n\nconst createImageFileInput = (editor: SylApi, config: ImageProps) => {\n const input = createFileInput({\n multiple: true,\n accept: config.accept || 'image/*',\n onChange: (e: Event) => {\n const files = getInputImageFiles(e);\n insertImageWithFiles(editor, files, config);\n },\n getContainer: () => editor.root,\n });\n\n return input;\n};\nclass ImageController extends SylController<ImageProps> {\n public fileInput: HTMLInputElement;\n\n public toolbar = {\n className: 'image',\n tooltip: 'image',\n icon: '' as any,\n handler: () => this.fileInput.click(),\n };\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n if (Object.keys(props).length) this.props = { ...BASE_CONFIG, ...props };\n this.fileInput = createImageFileInput(editor, this.props);\n editor.root.appendChild(this.fileInput);\n }\n\n public command = {\n insertImages: (editor: SylApi, files: File[]) => insertImageWithFiles(editor, files, this.props),\n updateImageUrl: (editor: SylApi, props: IUpdateImageProps) => updateImageUrl(editor, props, this.props),\n getConfiguration: () => this.props,\n };\n\n public eventHandler = {\n handleClickOn(\n editor: SylApi,\n view: EditorView,\n pos: number,\n node: ProsemirrorNode,\n nodePos: number,\n event: MouseEvent,\n ) {\n if (node.type.name === PLUGIN_NAME) {\n const caption = (event.target as HTMLElement).closest('input');\n if (caption) {\n if (caption) caption.focus();\n const newTextSelection = TextSelection.create(view.state.doc, nodePos);\n view.dispatch(view.state.tr.setSelection(newTextSelection));\n return true;\n }\n // when the currently selected image is a picture, but the system behaves as a cursor, correct the selection.(real is 'Range')\n const { state, dispatch } = view;\n const curSelection = window.getSelection();\n if (curSelection && curSelection.type === 'Caret') {\n dispatch(state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos)));\n return true;\n }\n return false;\n }\n return false;\n },\n handlePaste: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as ClipboardEvent;\n if ((this.props && !this.props.listenPaste) || !event.clipboardData) {\n return false;\n }\n const files = getImageFileList(event.clipboardData.files);\n const html = event.clipboardData.getData('text/html');\n const text = event.clipboardData.getData('text/plain');\n // if clipBoard get files and without any text and the src of img is a blob, then treat it as file\n if (\n !files.length ||\n text ||\n (html && (html.match(/<img/g)?.length !== 1 || !/<img[^>]*\\s+src=['\"]blob:[^>]*>/.test(html)))\n ) {\n return false;\n }\n editor.command.image!.insertImages(files);\n return true;\n },\n handleDOMEvents: {\n drop: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as DragEvent;\n\n if (view.dragging || (this.props && !this.props.listenDrop) || !event.dataTransfer) {\n return false;\n }\n const files: File[] = getImageFileList(event.dataTransfer.files);\n if (!files.length) return false;\n editor.command.image!.insertImages(files);\n e.preventDefault();\n return true;\n },\n },\n };\n\n public editorWillUnmount = () => {\n this.editor.root.removeChild(this.fileInput);\n };\n}\n\nclass Image extends BlockAtom<ImageAttrs> {\n public props: ImageProps;\n public name = PLUGIN_NAME;\n public traceSelection = false;\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n addAttrsByConfig(props.addAttributes, this);\n this.props = props;\n\n const { align, alt, ...rest } = this.attrs;\n // @ts-ignore\n this.attrs = { ...rest };\n if (!this.props.disableAlign) this.attrs.align = align;\n if (!this.props.disableCaption) this.attrs.alt = alt;\n }\n\n public parseDOM = [\n {\n tag: 'div.syl-image-wrapper',\n getAttrs: (dom: HTMLElement) =>\n parseSylDOM(dom, '.syl-image-fixer', '.syl-image-caption', this.props.addAttributes, getMaxWidth(this.editor)),\n },\n {\n tag: 'img',\n getAttrs: (dom: HTMLImageElement) => {\n if (!dom.src) return false;\n const attrWidth = dom.getAttribute('width');\n const attrHeight = dom.getAttribute('height');\n const maxWidth = getMaxWidth(this.editor);\n\n let width = getPx(dom.style.width || (attrWidth && `${attrWidth}px`) || '', 16);\n let height = getPx(dom.style.height || (attrHeight && `${attrHeight}px`) || '', 16);\n\n if (!width || isNaN(width)) width = 0;\n if (!height || isNaN(height)) height = 0;\n\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n const formattedAttrs = {\n src: dom.getAttribute('src') || '',\n alt: dom.getAttribute('alt') || '',\n name: dom.getAttribute('name') || '',\n align: (dom.getAttribute('align') || undefined) as any,\n width,\n height,\n };\n\n getFromDOMByConfig(this.props.addAttributes, dom, formattedAttrs);\n\n return formattedAttrs;\n },\n },\n ];\n public toDOM = (node: Node) => {\n const { align, width, height, ...attrs } = node.attrs;\n setDOMAttrByConfig(this.props.addAttributes, node, attrs);\n\n if (width) attrs.width = getFixSize(width);\n if (height) attrs.height = getFixSize(height);\n\n const renderSpec = ['img', attrs] as DOMOutputSpecArray;\n if (this.inline) return renderSpec;\n\n const alignAttrs = this.props.disableAlign ? {} : { align: align || 'center' };\n const outputArray = ['div', { class: 'syl-image-wrapper', ...alignAttrs }, renderSpec];\n attrs.alt && outputArray.push(['p', { class: 'syl-image-caption' }, attrs.alt]);\n return (outputArray as unknown) as DOMOutputSpecArray;\n };\n\n public attrs = {\n src: {\n default: '',\n },\n alt: {\n default: '',\n },\n name: {\n default: '',\n },\n width: {\n default: 0,\n },\n height: {\n default: 0,\n },\n align: {\n default: 'center' as const,\n },\n };\n}\n\nclass ImagePlugin extends SylPlugin<ImageProps> {\n public name = PLUGIN_NAME;\n public Controller = ImageController;\n public Schema = Image;\n}\n\nexport { Image, ImageAttrs, ImageController, ImagePlugin, ImageProps };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/atom/image/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAmG;AAEnG,uDAAiE;AAGjE,qCAQqB;AAErB,iCAOiB;AAEjB,IAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,IAAM,WAAW,GAAe;IAC9B,QAAQ,EAAE,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAnB,CAAmB;IACnC,kBAAkB,EAAE,KAAK;IACzB,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,MAAe;IAC3B,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,EAAE;IACb,cAAc,EAAE,GAAG;CACpB,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,MAAe;;IAClC,IAAI,QAAQ,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,CAAC,KAAK,0CAAE,gBAAgB,GAAG,QAAQ,CAAC;IAClE,IAAI,QAAQ,KAAK,SAAS,IAAI,MAAM,EAAE;QACpC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,EAAE,CAAC;KAC7C;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AACF,gEAAgE;AAChE,IAAM,WAAW,GAAG,UAClB,GAAgB,EAChB,QAAgB,EAChB,YAAoB,EACpB,aAA2C,EAC3C,QAAiB;IAEjB,IAAM,KAAK,GAAG,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAEzB,IAAM,OAAO,GAAG,GAAG,CAAC,aAAa,CAAC,YAAY,CAAmD,CAA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I,CAAC,KAAI,CAAC,KAAK,CAAC,YAAY;YAAE,KAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACvD,IAAI,CAAC,KAAI,CAAC,KAAK,CAAC,cAAc;YAAE,KAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC;;IACvD,CAAC;IA8EH,YAAC;AAAD,CAAC,AA7FD,CAAoB,mBAAS,GA6F5B;AAQQ,sBAAK;AANd;IAA0B,+BAAqB;IAA/C;QAAA,qEAIC;QAHQ,UAAI,GAAG,WAAW,CAAC;QACnB,gBAAU,GAAG,eAAe,CAAC;QAC7B,YAAM,GAAG,KAAK,CAAC;;IACxB,CAAC;IAAD,kBAAC;AAAD,CAAC,AAJD,CAA0B,mBAAS,GAIlC;AAE4C,kCAAW","sourcesContent":["import { BlockAtom, getPx, INodeInfo, SylApi, SylController, SylPlugin } from '@syllepsis/adapter';\nimport { DOMOutputSpecArray, Node, Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection, TextSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nimport {\n addAttrsByConfig,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n isMatchObject,\n isObjectURL,\n setDOMAttrByConfig,\n} from '../../utils';\nimport { ImageAttrs, ImageProps, IUpdateImageProps, TUploadDataType } from './types';\nimport {\n checkDomain,\n constructAttrs,\n correctSize,\n getImageFileList,\n getInputImageFiles,\n transformBlobFromObjectURL,\n} from './utils';\n\nconst PLUGIN_NAME = 'image';\n\nconst BASE_CONFIG: ImageProps = {\n uploader: () => Promise.resolve(''),\n uploadBeforeInsert: false,\n placeholder: '',\n uploadType: 'blob' as const,\n listenDrop: true,\n listenPaste: true,\n maxLength: 20,\n uploadMaxWidth: 375,\n};\n\nconst getMaxWidth = (editor?: SylApi) => {\n let maxWidth = editor?.command.image?.getConfiguration().maxWidth;\n if (maxWidth === undefined && editor) {\n maxWidth = editor.view.dom.scrollWidth - 40;\n }\n return maxWidth;\n};\n// parse the DOM of image which generated by the the ImagePlugin\nconst parseSylDOM = (\n dom: HTMLElement,\n fixClass: string,\n captionClass: string,\n addAttributes?: ImageProps['addAttributes'],\n maxWidth?: number,\n) => {\n const image = dom.querySelector('img');\n if (!image) return false;\n\n const caption = dom.querySelector(captionClass) as HTMLInputElement | HTMLParagraphElement | null;\n const fixer = dom.querySelector(fixClass);\n\n const alt = (caption && (caption.innerText || (caption as HTMLInputElement).value)) || '';\n const src = (image && image.src) || '';\n let width = image.width;\n let height = image.height;\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n let align: ImageAttrs['align'] = dom.getAttribute('align') as ImageAttrs['align'];\n if (!align && fixer) {\n const className = fixer.className;\n if (className.includes('left')) align = 'left';\n else if (className.includes('right')) align = 'right';\n }\n\n const name = image.getAttribute('name') || '';\n const attrs: ImageAttrs = { src, alt, width, height, align, name };\n addAttributes && getFromDOMByConfig(addAttributes, dom, attrs);\n\n return attrs;\n};\n\nconst uploadImg = async (editor: SylApi, src: string, fileName: string, config: ImageProps) => {\n let res: TUploadDataType = src;\n const { uploader, uploadType, onUploadError, deleteFailedUpload } = config;\n if (!uploader) throw new Error('Must provide uploader!');\n if (isObjectURL(src)) res = await transformBlobFromObjectURL(src);\n\n if (typeof res !== 'string' && uploadType === 'file') {\n res = new File([res as Blob], fileName, { type: res?.type });\n }\n try {\n const uploadRes = await uploader(res, {\n src,\n });\n if (typeof uploadRes === 'string') return { src: uploadRes || src };\n return { src, ...uploadRes };\n } catch (err) {\n if (deleteFailedUpload) {\n const nodeInfos = editor.getExistNodes(PLUGIN_NAME);\n nodeInfos.some(({ node, pos }) => {\n if (node.attrs.src === src) {\n editor.delete(pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (onUploadError) onUploadError(res, err);\n else throw err;\n }\n};\n\nconst insertImageInEditor = (\n editor: SylApi,\n dataInfos: { image?: HTMLImageElement; attrs?: { src: string; [key: string]: any } }[],\n config: Partial<ImageProps>,\n) => {\n const { state } = editor.view;\n const pos = state.selection.from;\n\n const imageType = state.schema.nodes?.image;\n const images = [...dataInfos];\n const insertNodes = { type: 'doc', content: [] as INodeInfo[] };\n // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order\n images.forEach(({ image, attrs }) => {\n if (!image || !attrs) return;\n const imageAttrs: Partial<ImageAttrs> = {\n width: config.uploadMaxWidth ? Math.min(image.naturalWidth, config.uploadMaxWidth) : image.naturalWidth,\n name: image.getAttribute('name') || '',\n alt: '',\n align: imageType?.attrs?.align?.default || 'center',\n ...attrs,\n };\n insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs });\n });\n if (insertNodes.content.length) editor.insert(insertNodes, pos);\n};\n\n// get the picture file and judge whether to upload it in advance\nconst insertImageWithFiles = async (editor: SylApi, files: File[], config: Partial<ImageProps>) => {\n const results = await Promise.all(\n files.map(\n f =>\n new Promise(async resolve => {\n if (config.checkBeforeInsert && !(await config.checkBeforeInsert(f))) return resolve({});\n\n const url = window.URL.createObjectURL(f);\n let attrs: undefined | { src: string } = { src: url };\n const image = document.createElement('img');\n\n image.onload = async () => {\n if (config.uploadBeforeInsert) {\n const uploadRes = await uploadImg(editor, url, f.name, config);\n if (!uploadRes) resolve({});\n else attrs = { ...attrs, ...uploadRes };\n }\n resolve({ attrs, image });\n };\n image.onerror = async e => {\n const { onUploadError } = config;\n onUploadError && onUploadError(f, e as Event);\n resolve({});\n };\n\n image.src = attrs.src;\n image.setAttribute('name', f.name);\n }) as Promise<{ image?: HTMLImageElement; attrs?: { src: string } }>,\n ),\n );\n\n insertImageInEditor(editor, results, config);\n};\n\nconst updateImageUrl = async (editor: SylApi, props: IUpdateImageProps, config: ImageProps) => {\n const { src, name } = props.attrs;\n if (props.state === undefined) props.state = {};\n const state = props.state;\n let imageAttrs: Partial<ImageAttrs> = {};\n\n try {\n // upload state, only single upload request is allowed in the same instance at the same time\n if (state.uploading || (!isObjectURL(src) && checkDomain(src, config))) {\n imageAttrs = await correctSize(props.attrs);\n } else {\n state.uploading = true;\n const attrs = await uploadImg(editor, src, name, config);\n state.uploading = false;\n if (!attrs) return;\n imageAttrs = await constructAttrs(props.attrs, attrs);\n }\n const nodePos = props.getPos();\n if (typeof nodePos !== 'number') return;\n const $pos = editor.view.state.doc.resolve(nodePos);\n const curNode = $pos.nodeAfter;\n // confirm the image node exist\n if (!curNode || curNode.type.name !== PLUGIN_NAME || curNode.attrs.src !== src) return;\n if (!isMatchObject({ ...props.attrs, ...imageAttrs }, props.attrs)) {\n editor.delete($pos.pos, 1, { addToHistory: false });\n editor.insertCard(PLUGIN_NAME, { ...props.attrs, ...imageAttrs }, { index: $pos.pos, deleteSelection: false });\n }\n } finally {\n state.uploading = false;\n }\n};\n\nconst createImageFileInput = (editor: SylApi, config: ImageProps) => {\n const input = createFileInput({\n multiple: true,\n accept: config.accept || 'image/*',\n onChange: (e: Event) => {\n const files = getInputImageFiles(e);\n insertImageWithFiles(editor, files, config);\n },\n getContainer: () => editor.root,\n });\n\n return input;\n};\nclass ImageController extends SylController<ImageProps> {\n public fileInput: HTMLInputElement;\n\n public toolbar = {\n className: 'image',\n tooltip: 'image',\n icon: '' as any,\n handler: () => this.fileInput.click(),\n };\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n if (Object.keys(props).length) this.props = { ...BASE_CONFIG, ...props };\n this.fileInput = createImageFileInput(editor, this.props);\n editor.root.appendChild(this.fileInput);\n }\n\n public command = {\n insertImages: (editor: SylApi, files: File[]) => insertImageWithFiles(editor, files, this.props),\n updateImageUrl: (editor: SylApi, props: IUpdateImageProps) => updateImageUrl(editor, props, this.props),\n getConfiguration: () => this.props,\n };\n\n public eventHandler = {\n handleClickOn(\n editor: SylApi,\n view: EditorView,\n pos: number,\n node: ProsemirrorNode,\n nodePos: number,\n event: MouseEvent,\n ) {\n if (node.type.name === PLUGIN_NAME) {\n const caption = (event.target as HTMLElement).closest('input');\n if (caption) {\n if (caption) caption.focus();\n const newTextSelection = TextSelection.create(view.state.doc, nodePos);\n view.dispatch(view.state.tr.setSelection(newTextSelection));\n return true;\n }\n // when the currently selected image is a picture, but the system behaves as a cursor, correct the selection.(real is 'Range')\n const { state, dispatch } = view;\n const curSelection = window.getSelection();\n if (curSelection && curSelection.type === 'Caret') {\n dispatch(state.tr.setSelection(NodeSelection.create(view.state.doc, nodePos)));\n return true;\n }\n return false;\n }\n return false;\n },\n handlePaste: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as ClipboardEvent;\n if ((this.props && !this.props.listenPaste) || !event.clipboardData) {\n return false;\n }\n const files = getImageFileList(event.clipboardData.files);\n const html = event.clipboardData.getData('text/html');\n const text = event.clipboardData.getData('text/plain');\n // if clipBoard get files and without any text and the src of img is a blob, then treat it as file\n if (\n !files.length ||\n text ||\n (html && (html.match(/<img/g)?.length !== 1 || !/<img[^>]*\\s+src=['\"]blob:[^>]*>/.test(html)))\n ) {\n return false;\n }\n editor.command.image!.insertImages(files);\n return true;\n },\n handleDOMEvents: {\n drop: (editor: SylApi, view: EditorView, e: Event) => {\n const event = e as DragEvent;\n\n if (view.dragging || (this.props && !this.props.listenDrop) || !event.dataTransfer) {\n return false;\n }\n const files: File[] = getImageFileList(event.dataTransfer.files);\n if (!files.length) return false;\n editor.command.image!.insertImages(files);\n e.preventDefault();\n return true;\n },\n },\n };\n\n public editorWillUnmount = () => {\n this.editor.root.removeChild(this.fileInput);\n };\n}\n\nclass Image extends BlockAtom<ImageAttrs> {\n public props: ImageProps;\n public name = PLUGIN_NAME;\n public traceSelection = false;\n\n constructor(editor: SylApi, props: ImageProps) {\n super(editor, props);\n addAttrsByConfig(props.addAttributes, this);\n this.props = props;\n\n const { align, alt, ...rest } = this.attrs;\n // @ts-ignore\n this.attrs = { ...rest };\n if (!this.props.disableAlign) this.attrs.align = align;\n if (!this.props.disableCaption) this.attrs.alt = alt;\n }\n\n public parseDOM = [\n {\n tag: 'div.syl-image-wrapper',\n getAttrs: (dom: HTMLElement) =>\n parseSylDOM(dom, '.syl-image-fixer', '.syl-image-caption', this.props.addAttributes, getMaxWidth(this.editor)),\n },\n {\n tag: 'img',\n getAttrs: (dom: HTMLImageElement) => {\n if (!dom.src) return false;\n const attrWidth = dom.getAttribute('width');\n const attrHeight = dom.getAttribute('height');\n const maxWidth = getMaxWidth(this.editor);\n\n let width = getPx(dom.style.width || (attrWidth && `${attrWidth}px`) || '', 16);\n let height = getPx(dom.style.height || (attrHeight && `${attrHeight}px`) || '', 16);\n\n if (!width || isNaN(width)) width = 0;\n if (!height || isNaN(height)) height = 0;\n\n if (maxWidth && width > maxWidth) {\n if (height) height = height / (width / maxWidth);\n width = maxWidth;\n }\n\n const formattedAttrs = {\n src: dom.getAttribute('src') || '',\n alt: dom.getAttribute('alt') || '',\n name: dom.getAttribute('name') || '',\n align: (dom.getAttribute('align') || undefined) as any,\n width,\n height,\n };\n\n getFromDOMByConfig(this.props.addAttributes, dom, formattedAttrs);\n\n return formattedAttrs;\n },\n },\n ];\n public toDOM = (node: Node) => {\n const { align, width, height, ...attrs } = node.attrs;\n setDOMAttrByConfig(this.props.addAttributes, node, attrs);\n\n if (width) attrs.width = getFixSize(width);\n if (height) attrs.height = getFixSize(height);\n\n const renderSpec = ['img', attrs] as DOMOutputSpecArray;\n if (this.inline) return renderSpec;\n\n const alignAttrs = this.props.disableAlign ? {} : { align: align || 'center' };\n const outputArray = ['div', { class: 'syl-image-wrapper', ...alignAttrs }, renderSpec];\n attrs.alt && outputArray.push(['p', { class: 'syl-image-caption' }, attrs.alt]);\n return (outputArray as unknown) as DOMOutputSpecArray;\n };\n\n public attrs = {\n src: {\n default: '',\n },\n alt: {\n default: '',\n },\n name: {\n default: '',\n },\n width: {\n default: 0,\n },\n height: {\n default: 0,\n },\n align: {\n default: 'center' as const,\n },\n };\n}\n\nclass ImagePlugin extends SylPlugin<ImageProps> {\n public name = PLUGIN_NAME;\n public Controller = ImageController;\n public Schema = Image;\n}\n\nexport { Image, ImageAttrs, ImageController, ImagePlugin, ImageProps };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignCenterPlugin extends SylPlugin { | ||
| declare class AlignCenterPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignCenterController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-center/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAA4C;AAU5C;IAAoC,yCAAe;IAAnD;QAAA,qEAEC;QADQ,WAAK,GAAG,QAAiB,CAAC;;IACnC,CAAC;IAAD,4BAAC;AAAD,CAAC,AAFD,CAAoC,wBAAe,GAElD;AAED;IAAgC,qCAAS;IAAzC;QAAA,qEAGC;QAFQ,UAAI,GAAG,cAAc,CAAC;QACtB,gBAAU,GAAG,qBAAqB,CAAC;;IAC5C,CAAC;IAAD,wBAAC;AAAD,CAAC,AAHD,CAAgC,mBAAS,GAGxC;AAEQ,8CAAiB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_center?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignCenterController extends AlignController {\n public value = 'center' as const;\n}\n\nclass AlignCenterPlugin extends SylPlugin {\n public name = 'align_center';\n public Controller = AlignCenterController;\n}\n\nexport { AlignCenterPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-center/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAAyD;AAUzD;IAAoC,yCAAe;IAAnD;QAAA,qEAEC;QADQ,WAAK,GAAG,QAAiB,CAAC;;IACnC,CAAC;IAAD,4BAAC;AAAD,CAAC,AAFD,CAAoC,wBAAe,GAElD;AAED;IAAgC,qCAAsB;IAAtD;QAAA,qEAGC;QAFQ,UAAI,GAAG,cAAc,CAAC;QACtB,gBAAU,GAAG,qBAAqB,CAAC;;IAC5C,CAAC;IAAD,wBAAC;AAAD,CAAC,AAHD,CAAgC,mBAAS,GAGxC;AAEQ,8CAAiB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_center?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignCenterController extends AlignController {\n public value = 'center' as const;\n}\n\nclass AlignCenterPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_center';\n public Controller = AlignCenterController;\n}\n\nexport { AlignCenterPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignJustifyPlugin extends SylPlugin { | ||
| declare class AlignJustifyPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignJustifyController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-justify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAA4C;AAU5C;IAAqC,0CAAe;IAApD;QAAA,qEAEC;QADQ,WAAK,GAAG,SAAkB,CAAC;;IACpC,CAAC;IAAD,6BAAC;AAAD,CAAC,AAFD,CAAqC,wBAAe,GAEnD;AAED;IAAiC,sCAAS;IAA1C;QAAA,qEAGC;QAFQ,UAAI,GAAG,eAAe,CAAC;QACvB,gBAAU,GAAG,sBAAsB,CAAC;;IAC7C,CAAC;IAAD,yBAAC;AAAD,CAAC,AAHD,CAAiC,mBAAS,GAGzC;AAEQ,gDAAkB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_justify?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignJustifyController extends AlignController {\n public value = 'justify' as const;\n}\n\nclass AlignJustifyPlugin extends SylPlugin {\n public name = 'align_justify';\n public Controller = AlignJustifyController;\n}\n\nexport { AlignJustifyPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-justify/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAAyD;AAUzD;IAAqC,0CAAe;IAApD;QAAA,qEAEC;QADQ,WAAK,GAAG,SAAkB,CAAC;;IACpC,CAAC;IAAD,6BAAC;AAAD,CAAC,AAFD,CAAqC,wBAAe,GAEnD;AAED;IAAiC,sCAAsB;IAAvD;QAAA,qEAGC;QAFQ,UAAI,GAAG,eAAe,CAAC;QACvB,gBAAU,GAAG,sBAAsB,CAAC;;IAC7C,CAAC;IAAD,yBAAC;AAAD,CAAC,AAHD,CAAiC,mBAAS,GAGzC;AAEQ,gDAAkB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_justify?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignJustifyController extends AlignController {\n public value = 'justify' as const;\n}\n\nclass AlignJustifyPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_justify';\n public Controller = AlignJustifyController;\n}\n\nexport { AlignJustifyPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignLeftPlugin extends SylPlugin { | ||
| declare class AlignLeftPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignLeftController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-left/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAA4C;AAS5C;IAAkC,uCAAe;IAAjD;QAAA,qEAEC;QADQ,iBAAW,GAAG,KAAK,CAAC;;IAC7B,CAAC;IAAD,0BAAC;AAAD,CAAC,AAFD,CAAkC,wBAAe,GAEhD;AAED;IAA8B,mCAAS;IAAvC;QAAA,qEAGC;QAFQ,UAAI,GAAG,YAAY,CAAC;QACpB,gBAAU,GAAG,mBAAmB,CAAC;;IAC1C,CAAC;IAAD,sBAAC;AAAD,CAAC,AAHD,CAA8B,mBAAS,GAGtC;AAEQ,0CAAe","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_left?: {\n setStyle: () => void;\n };\n }\n}\nclass AlignLeftController extends AlignController {\n public checkActive = false;\n}\n\nclass AlignLeftPlugin extends SylPlugin {\n public name = 'align_left';\n public Controller = AlignLeftController;\n}\n\nexport { AlignLeftPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-left/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAAyD;AASzD;IAAkC,uCAAe;IAAjD;QAAA,qEAEC;QADQ,iBAAW,GAAG,KAAK,CAAC;;IAC7B,CAAC;IAAD,0BAAC;AAAD,CAAC,AAFD,CAAkC,wBAAe,GAEhD;AAED;IAA8B,mCAAsB;IAApD;QAAA,qEAGC;QAFQ,UAAI,GAAG,YAAY,CAAC;QACpB,gBAAU,GAAG,mBAAmB,CAAC;;IAC1C,CAAC;IAAD,sBAAC;AAAD,CAAC,AAHD,CAA8B,mBAAS,GAGtC;AAEQ,0CAAe","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_left?: {\n setStyle: () => void;\n };\n }\n}\nclass AlignLeftController extends AlignController {\n public checkActive = false;\n}\n\nclass AlignLeftPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_left';\n public Controller = AlignLeftController;\n}\n\nexport { AlignLeftPlugin };\n"]} |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
| declare module '@syllepsis/adapter' { | ||
@@ -13,3 +13,3 @@ interface ISylApiCommand { | ||
| } | ||
| declare class AlignRightPlugin extends SylPlugin { | ||
| declare class AlignRightPlugin extends SylPlugin<IAlignProps> { | ||
| name: string; | ||
@@ -16,0 +16,0 @@ Controller: typeof AlignRightController; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-right/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAA4C;AAU5C;IAAmC,wCAAe;IAAlD;QAAA,qEAEC;QADQ,WAAK,GAAG,OAAgB,CAAC;;IAClC,CAAC;IAAD,2BAAC;AAAD,CAAC,AAFD,CAAmC,wBAAe,GAEjD;AAED;IAA+B,oCAAS;IAAxC;QAAA,qEAGC;QAFQ,UAAI,GAAG,aAAa,CAAC;QACrB,gBAAU,GAAG,oBAAoB,CAAC;;IAC3C,CAAC;IAAD,uBAAC;AAAD,CAAC,AAHD,CAA+B,mBAAS,GAGvC;AAEQ,4CAAgB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_right?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignRightController extends AlignController {\n public value = 'right' as const;\n}\n\nclass AlignRightPlugin extends SylPlugin {\n public name = 'align_right';\n public Controller = AlignRightController;\n}\n\nexport { AlignRightPlugin };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extension/align-right/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA+C;AAE/C,oCAAyD;AAUzD;IAAmC,wCAAe;IAAlD;QAAA,qEAEC;QADQ,WAAK,GAAG,OAAgB,CAAC;;IAClC,CAAC;IAAD,2BAAC;AAAD,CAAC,AAFD,CAAmC,wBAAe,GAEjD;AAED;IAA+B,oCAAsB;IAArD;QAAA,qEAGC;QAFQ,UAAI,GAAG,aAAa,CAAC;QACrB,gBAAU,GAAG,oBAAoB,CAAC;;IAC3C,CAAC;IAAD,uBAAC;AAAD,CAAC,AAHD,CAA+B,mBAAS,GAGvC;AAEQ,4CAAgB","sourcesContent":["import { SylPlugin } from '@syllepsis/adapter';\n\nimport { AlignController, IAlignProps } from '../common';\n\ndeclare module '@syllepsis/adapter' {\n interface ISylApiCommand {\n align_right?: {\n setStyle: () => void;\n };\n }\n}\n\nclass AlignRightController extends AlignController {\n public value = 'right' as const;\n}\n\nclass AlignRightPlugin extends SylPlugin<IAlignProps> {\n public name = 'align_right';\n public Controller = AlignRightController;\n}\n\nexport { AlignRightPlugin };\n"]} |
| import { SylApi, SylController } from '@syllepsis/adapter'; | ||
| declare class AlignController extends SylController { | ||
| interface IAlignProps { | ||
| /** includes all related nodes not just the top child node that supports `align` attributes */ | ||
| inclusive?: boolean; | ||
| } | ||
| declare class AlignController extends SylController<IAlignProps> { | ||
| checkActive: boolean; | ||
@@ -14,2 +18,2 @@ value: 'left' | 'right' | 'center' | 'justify'; | ||
| } | ||
| export { AlignController }; | ||
| export { AlignController, IAlignProps }; |
@@ -29,11 +29,13 @@ "use strict"; | ||
| _this.toolbar = { | ||
| handler: function (editor) { return _this.command.setStyle(editor); } | ||
| handler: function (editor) { return _this.command.setStyle(editor); }, | ||
| }; | ||
| _this.command = { | ||
| setStyle: function (editor) { | ||
| (0, utils_1.setAlign)(editor.view, _this.value); | ||
| (0, utils_1.setAlign)(editor.view, _this.value, _this.props.inclusive); | ||
| editor.focus(); | ||
| } | ||
| }, | ||
| }; | ||
| _this.disable = function (editor) { return !(editor.view.state.selection instanceof prosemirror_state_1.AllSelection) && !(0, utils_1.checkParentSupportAttr)(editor.view, 'align'); }; | ||
| _this.disable = function (editor) { | ||
| return !(editor.view.state.selection instanceof prosemirror_state_1.AllSelection) && !(0, utils_1.checkParentSupportAttr)(editor.view, 'align'); | ||
| }; | ||
| _this.active = function () { return (_this.checkActive ? (0, utils_1.checkParentHaveAttr)(_this.editor.view, 'align', _this.value) : false); }; | ||
@@ -40,0 +42,0 @@ return _this; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/extension/common/align/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA2D;AAC3D,uDAAiD;AAEjD,wCAAuF;AAEvF;IAA8B,mCAAa;IAA3C;QAAA,qEAiBC;QAhBQ,iBAAW,GAAG,IAAI,CAAC;QACnB,WAAK,GAA4C,MAAM,CAAC;QAExD,aAAO,GAAG;YACf,OAAO,EAAE,UAAC,MAAc,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAA7B,CAA6B;SAC3D,CAAC;QAEK,aAAO,GAAG;YACf,QAAQ,EAAE,UAAC,MAAc;gBACvB,IAAA,gBAAQ,EAAC,MAAM,CAAC,IAAI,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC;gBAClC,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;SACF,CAAC;QAEK,aAAO,GAAG,UAAC,MAAc,IAAK,OAAA,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,YAAY,gCAAY,CAAC,IAAI,CAAC,IAAA,8BAAsB,EAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAAvG,CAAuG,CAAC;QACtI,YAAM,GAAG,cAAM,OAAA,CAAC,KAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,2BAAmB,EAAC,KAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAvF,CAAuF,CAAC;;IAChH,CAAC;IAAD,sBAAC;AAAD,CAAC,AAjBD,CAA8B,uBAAa,GAiB1C;AAEQ,0CAAe","sourcesContent":["import { SylApi, SylController } from '@syllepsis/adapter';\nimport { AllSelection } from 'prosemirror-state';\n\nimport { checkParentHaveAttr, checkParentSupportAttr, setAlign } from '../../../utils';\n\nclass AlignController extends SylController {\n public checkActive = true;\n public value: 'left' | 'right' | 'center' | 'justify' = 'left';\n\n public toolbar = {\n handler: (editor: SylApi) => this.command.setStyle(editor)\n };\n\n public command = {\n setStyle: (editor: SylApi) => {\n setAlign(editor.view, this.value);\n editor.focus();\n }\n };\n\n public disable = (editor: SylApi) => !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align');\n public active = () => (this.checkActive ? checkParentHaveAttr(this.editor.view, 'align', this.value) : false);\n}\n\nexport { AlignController };\n"]} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/extension/common/align/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,8CAA2D;AAC3D,uDAAiD;AAEjD,wCAAuF;AAOvF;IAA8B,mCAA0B;IAAxD;QAAA,qEAkBC;QAjBQ,iBAAW,GAAG,IAAI,CAAC;QACnB,WAAK,GAA4C,MAAM,CAAC;QAExD,aAAO,GAAG;YACf,OAAO,EAAE,UAAC,MAAc,IAAK,OAAA,KAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAA7B,CAA6B;SAC3D,CAAC;QAEK,aAAO,GAAG;YACf,QAAQ,EAAE,UAAC,MAAc;gBACvB,IAAA,gBAAQ,EAAC,MAAM,CAAC,IAAI,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;gBACxD,MAAM,CAAC,KAAK,EAAE,CAAC;YACjB,CAAC;SACF,CAAC;QAEK,aAAO,GAAG,UAAC,MAAc;YAC9B,OAAA,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,YAAY,gCAAY,CAAC,IAAI,CAAC,IAAA,8BAAsB,EAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC;QAAvG,CAAuG,CAAC;QACnG,YAAM,GAAG,cAAM,OAAA,CAAC,KAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAA,2BAAmB,EAAC,KAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAvF,CAAuF,CAAC;;IAChH,CAAC;IAAD,sBAAC;AAAD,CAAC,AAlBD,CAA8B,uBAAa,GAkB1C;AAEQ,0CAAe","sourcesContent":["import { SylApi, SylController } from '@syllepsis/adapter';\nimport { AllSelection } from 'prosemirror-state';\n\nimport { checkParentHaveAttr, checkParentSupportAttr, setAlign } from '../../../utils';\n\ninterface IAlignProps {\n /** includes all related nodes not just the top child node that supports `align` attributes */\n inclusive?: boolean;\n}\n\nclass AlignController extends SylController<IAlignProps> {\n public checkActive = true;\n public value: 'left' | 'right' | 'center' | 'justify' = 'left';\n\n public toolbar = {\n handler: (editor: SylApi) => this.command.setStyle(editor),\n };\n\n public command = {\n setStyle: (editor: SylApi) => {\n setAlign(editor.view, this.value, this.props.inclusive);\n editor.focus();\n },\n };\n\n public disable = (editor: SylApi) =>\n !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align');\n public active = () => (this.checkActive ? checkParentHaveAttr(this.editor.view, 'align', this.value) : false);\n}\n\nexport { AlignController, IAlignProps };\n"]} |
@@ -7,3 +7,3 @@ import { SylApi, Types } from '@syllepsis/adapter'; | ||
| declare const checkParentSupportAttr: (view: EditorView, attrName: string) => boolean; | ||
| declare const setAlign: (view: EditorView, align: 'left' | 'center' | 'right' | 'justify') => boolean; | ||
| declare const setAlign: (view: EditorView, align: 'left' | 'center' | 'right' | 'justify', inclusive?: boolean) => boolean; | ||
| declare const checkParentHaveAttr: (view: EditorView, attrName: string, attrVal: string) => boolean; | ||
@@ -36,2 +36,2 @@ declare type IUserAttrsConfig = Types.StringMap<{ | ||
| }) => Promise<void>; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, IUserAttrsConfig, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler }; | ||
| export { addAttrsByConfig, checkMarkDisable, checkParentHaveAttr, checkParentSupportAttr, createFileInput, getFixSize, getFromDOMByConfig, getMarkDisable, isMatchObject, IUserAttrsConfig, keymapToggleMark, setAlign, setDOMAttrByConfig, simpleUploadHandler, }; |
@@ -91,3 +91,4 @@ "use strict"; | ||
| exports.checkParentSupportAttr = checkParentSupportAttr; | ||
| var setAlign = function (view, align) { | ||
| var setAlign = function (view, align, inclusive) { | ||
| if (inclusive === void 0) { inclusive = false; } | ||
| var state = view.state, dispatch = view.dispatch; | ||
@@ -102,5 +103,5 @@ var tr = state.tr; | ||
| state.doc.nodesBetween(from, to, function (node, nodePos) { | ||
| if (node.isTextblock || node.attrs.align !== undefined) { | ||
| if (node.attrs.align !== undefined) { | ||
| tr.setNodeMarkup(nodePos, undefined, __assign(__assign({}, node.attrs), { align: align })); | ||
| return false; | ||
| return inclusive; | ||
| } | ||
@@ -107,0 +108,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/ut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AAG,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;iBACrD;gBACa,qBAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,EAAA;;gBAApC,KAAK,GAAG,SAA4B;gBAC1C,IAAI,CAAC,kBAAkB,EAAE;oBACvB,KAAK,GAAG,CAAC,CAAC,CAAC;oBACX,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAA,GAAG;wBACjC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE;4BAC9B,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC;4BAChB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;4BACnD,OAAO,IAAI,CAAC;yBACb;oBACH,CAAC,CAAC,CAAC;iBACJ;gBACD,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACvB,KAAK,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAY,EAAE,KAAK,CAAC,CAAC;iBAC5D;gBACD,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;;;;KACjC,CAAC;AAiBA,kDAAmB","sourcesContent":["import { SylApi, Types } from '@syllepsis/adapter';\nimport { Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nconst getMarkDisable = (excludeMarks: string | undefined, markName: string) => {\n if (!excludeMarks) return false;\n if (excludeMarks === '_') return true;\n if (excludeMarks.split(/\\s/).includes(markName)) return true;\n return false;\n};\n\nconst checkMarkDisable = (view: EditorView, markName: string) => {\n const { $from } = view.state.selection;\n if ($from.parent.type.spec.code) return true;\n const excludeMarks = $from.parent.type.spec.excludeMarks;\n if (!getMarkDisable(excludeMarks, markName)) {\n if ($from.depth > 1) {\n const parentExcludeMarks = $from.node($from.depth - 1).type.spec.excludeMarks;\n return getMarkDisable(parentExcludeMarks, markName);\n }\n return false;\n }\n\n return true;\n};\n\nconst checkSupportAttr = (node: ProsemirrorNode, attrName: string) => node.attrs[attrName] !== undefined;\n\nconst checkParentSupportAttr = (view: EditorView, attrName: string) => {\n const { selection } = view.state;\n if (selection instanceof NodeSelection) {\n return checkSupportAttr(selection.node, attrName);\n }\n const { $from, $to } = selection;\n let isSupport = checkSupportAttr(selection.$from.node(), attrName);\n if (!isSupport && $from.nodeAfter && $from.pos === $to.pos) {\n isSupport = checkSupportAttr($from.nodeAfter, attrName);\n }\n return isSupport;\n};\n\nconst setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify') => {\n const { state, dispatch } = view;\n const tr = state.tr;\n const { ranges } = state.selection;\n if (!ranges.length) return false;\n ranges.forEach(range => {\n const from = range.$from.pos;\n const to = range.$to.pos;\n state.doc.nodesBetween(from, to, (node, nodePos) => {\n if (node.isTextblock || node.attrs.align !== undefined) {\n tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, align });\n return false;\n }\n });\n });\n dispatch(tr);\n return true;\n};\n\nconst checkParentHaveAttr = (view: EditorView, attrName: string, attrVal: string) =>\n view.state.selection.$from.parent.attrs[attrName] === attrVal;\n\ntype IUserAttrsConfig = Types.StringMap<{\n // used to extend default attrs\n default: any;\n [key: string]: any;\n getFromDOM: (dom: HTMLElement) => any | void | undefined; // used in `parseDOM`\n setDOMAttr: (value: string, attrs: Types.StringMap<any>) => void; // used in `toDOM`\n}>;\n\n// add user configuration to attrs attribute\nconst addAttrsByConfig = (config: IUserAttrsConfig = {}, schema: Types.StringMap<any>) => {\n if (!schema.attrs) schema.attrs = {};\n Object.keys(config).forEach(name => {\n Object.keys(config[name]).forEach(spec => {\n if (spec === 'getFromDOM' || spec === 'setDOMAttr') return;\n if (!schema.attrs[name]) schema.attrs[name] = {};\n schema.attrs[name][spec] = config[name][spec];\n });\n });\n};\n\n// uses the default value when return undefined\nconst getFromDOMByConfig = (config: IUserAttrsConfig = {}, dom: HTMLElement, parseAttrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => {\n const value = config[name].getFromDOM(dom);\n if (value !== undefined) Object.assign(parseAttrs, { [name]: value });\n });\n\n// used to construct dom in `toDOM`\nconst setDOMAttrByConfig = (config: IUserAttrsConfig = {}, node: ProsemirrorNode, attrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => config[name].setDOMAttr(node.attrs[name], attrs));\n\n// Keep the decimal point\nconst getFixSize = (num: number, count = 3) => Number(num.toFixed(count).replace(/\\.?0+$/, ''));\n\nconst createFileInput = ({\n multiple = false,\n accept,\n onChange,\n getContainer = () => document.body,\n}: {\n multiple: boolean;\n accept: string;\n onChange: (e: Event) => void;\n getContainer: () => HTMLElement;\n}) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.multiple = multiple;\n input.accept = accept;\n input.style.display = 'none';\n input.addEventListener('change', e => {\n onChange(e);\n (e.target as HTMLInputElement).value = '';\n });\n getContainer().appendChild(input);\n return input;\n};\n\nconst isMatchObject = (objStatic: any, objCompare: any) => {\n if (objStatic === objCompare) return true;\n if (!(objStatic && typeof objStatic === 'object') || !(objCompare && typeof objCompare === 'object')) return false;\n const isArray = Array.isArray(objStatic);\n if (Array.isArray(objCompare) !== isArray) return false;\n if (isArray) {\n if (objStatic.length !== objCompare.length) return false;\n for (let i = 0; i < objStatic.length; i++) if (!isMatchObject(objStatic[i], objCompare[i])) return false;\n } else {\n for (const p in objStatic) if (!(p in objCompare) || !isMatchObject(objStatic[p], objCompare[p])) return false;\n }\n return true;\n};\n\nconst keymapToggleMark = (name: string) => (editor: SylApi) => {\n const isActive = editor.isActive(name);\n editor.setFormat({ [name]: !isActive });\n return true;\n};\n\nconst simpleUploadHandler = async (config: {\n name: string;\n target: HTMLInputElement;\n uploader: (file: File, editor: SylApi) => Promise<any>;\n uploadBeforeInsert: boolean;\n editor: SylApi;\n getAttrs: (url: string, file: File) => Record<string, any>;\n}) => {\n const { name, target, uploader, getAttrs, uploadBeforeInsert, editor } = config;\n if (!target.files || !target.files.length) return;\n const file = target.files[0];\n let index = editor.getSelection().index;\n let url = '';\n if (!uploadBeforeInsert) {\n url = URL.createObjectURL(file);\n editor.insertCard(name, getAttrs(url, file), index);\n }\n const attrs = await uploader(file, editor);\n if (!uploadBeforeInsert) {\n index = -1;\n editor.getExistNodes(name).some(val => {\n if (val.node.attrs.src === url) {\n index = val.pos;\n editor.delete(val.pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (attrs && index > -1) {\n index > -1 && editor.insertCard(name, attrs as any, index);\n }\n url && URL.revokeObjectURL(url);\n};\n\n\nexport {\n addAttrsByConfig,\n checkMarkDisable,\n checkParentHaveAttr,\n checkParentSupportAttr,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n getMarkDisable,\n isMatchObject,\n IUserAttrsConfig,\n keymapToggleMark,\n setAlign,\n setDOMAttrByConfig,\n simpleUploadHandler\n};\n"]} | ||
| {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/utils/tools.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uDAAkD;AAGlD,IAAM,cAAc,GAAG,UAAC,YAAgC,EAAE,QAAgB;IACxE,IAAI,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAChC,IAAI,YAAY,KAAK,GAAG;QAAE,OAAO,IAAI,CAAC;IACtC,IAAI,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AA8KA,wCAAc;AA5KhB,IAAM,gBAAgB,GAAG,UAAC,IAAgB,EAAE,QAAgB;IAClD,IAAA,KAAK,GAAK,IAAI,CAAC,KAAK,CAAC,SAAS,MAAzB,CAA0B;IACvC,IAAI,KAA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AC;yBACb;oBACH,CAAC,CAAC,CAAC;iBACJ;gBACD,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACvB,KAAK,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAY,EAAE,KAAK,CAAC,CAAC;iBAC5D;gBACD,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;;;;KACjC,CAAC;AAgBA,kDAAmB","sourcesContent":["import { SylApi, Types } from '@syllepsis/adapter';\nimport { Node as ProsemirrorNode } from 'prosemirror-model';\nimport { NodeSelection } from 'prosemirror-state';\nimport { EditorView } from 'prosemirror-view';\n\nconst getMarkDisable = (excludeMarks: string | undefined, markName: string) => {\n if (!excludeMarks) return false;\n if (excludeMarks === '_') return true;\n if (excludeMarks.split(/\\s/).includes(markName)) return true;\n return false;\n};\n\nconst checkMarkDisable = (view: EditorView, markName: string) => {\n const { $from } = view.state.selection;\n if ($from.parent.type.spec.code) return true;\n const excludeMarks = $from.parent.type.spec.excludeMarks;\n if (!getMarkDisable(excludeMarks, markName)) {\n if ($from.depth > 1) {\n const parentExcludeMarks = $from.node($from.depth - 1).type.spec.excludeMarks;\n return getMarkDisable(parentExcludeMarks, markName);\n }\n return false;\n }\n\n return true;\n};\n\nconst checkSupportAttr = (node: ProsemirrorNode, attrName: string) => node.attrs[attrName] !== undefined;\n\nconst checkParentSupportAttr = (view: EditorView, attrName: string) => {\n const { selection } = view.state;\n if (selection instanceof NodeSelection) {\n return checkSupportAttr(selection.node, attrName);\n }\n const { $from, $to } = selection;\n let isSupport = checkSupportAttr(selection.$from.node(), attrName);\n if (!isSupport && $from.nodeAfter && $from.pos === $to.pos) {\n isSupport = checkSupportAttr($from.nodeAfter, attrName);\n }\n return isSupport;\n};\n\nconst setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify', inclusive = false) => {\n const { state, dispatch } = view;\n const tr = state.tr;\n const { ranges } = state.selection;\n if (!ranges.length) return false;\n ranges.forEach(range => {\n const from = range.$from.pos;\n const to = range.$to.pos;\n state.doc.nodesBetween(from, to, (node, nodePos) => {\n if (node.attrs.align !== undefined) {\n tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, align });\n return inclusive;\n }\n });\n });\n dispatch(tr);\n return true;\n};\n\nconst checkParentHaveAttr = (view: EditorView, attrName: string, attrVal: string) =>\n view.state.selection.$from.parent.attrs[attrName] === attrVal;\n\ntype IUserAttrsConfig = Types.StringMap<{\n // used to extend default attrs\n default: any;\n [key: string]: any;\n getFromDOM: (dom: HTMLElement) => any | void | undefined; // used in `parseDOM`\n setDOMAttr: (value: string, attrs: Types.StringMap<any>) => void; // used in `toDOM`\n}>;\n\n// add user configuration to attrs attribute\nconst addAttrsByConfig = (config: IUserAttrsConfig = {}, schema: Types.StringMap<any>) => {\n if (!schema.attrs) schema.attrs = {};\n Object.keys(config).forEach(name => {\n Object.keys(config[name]).forEach(spec => {\n if (spec === 'getFromDOM' || spec === 'setDOMAttr') return;\n if (!schema.attrs[name]) schema.attrs[name] = {};\n schema.attrs[name][spec] = config[name][spec];\n });\n });\n};\n\n// uses the default value when return undefined\nconst getFromDOMByConfig = (config: IUserAttrsConfig = {}, dom: HTMLElement, parseAttrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => {\n const value = config[name].getFromDOM(dom);\n if (value !== undefined) Object.assign(parseAttrs, { [name]: value });\n });\n\n// used to construct dom in `toDOM`\nconst setDOMAttrByConfig = (config: IUserAttrsConfig = {}, node: ProsemirrorNode, attrs: Types.StringMap<any>) =>\n Object.keys(config).forEach(name => config[name].setDOMAttr(node.attrs[name], attrs));\n\n// Keep the decimal point\nconst getFixSize = (num: number, count = 3) => Number(num.toFixed(count).replace(/\\.?0+$/, ''));\n\nconst createFileInput = ({\n multiple = false,\n accept,\n onChange,\n getContainer = () => document.body,\n}: {\n multiple: boolean;\n accept: string;\n onChange: (e: Event) => void;\n getContainer: () => HTMLElement;\n}) => {\n const input = document.createElement('input');\n input.type = 'file';\n input.multiple = multiple;\n input.accept = accept;\n input.style.display = 'none';\n input.addEventListener('change', e => {\n onChange(e);\n (e.target as HTMLInputElement).value = '';\n });\n getContainer().appendChild(input);\n return input;\n};\n\nconst isMatchObject = (objStatic: any, objCompare: any) => {\n if (objStatic === objCompare) return true;\n if (!(objStatic && typeof objStatic === 'object') || !(objCompare && typeof objCompare === 'object')) return false;\n const isArray = Array.isArray(objStatic);\n if (Array.isArray(objCompare) !== isArray) return false;\n if (isArray) {\n if (objStatic.length !== objCompare.length) return false;\n for (let i = 0; i < objStatic.length; i++) if (!isMatchObject(objStatic[i], objCompare[i])) return false;\n } else {\n for (const p in objStatic) if (!(p in objCompare) || !isMatchObject(objStatic[p], objCompare[p])) return false;\n }\n return true;\n};\n\nconst keymapToggleMark = (name: string) => (editor: SylApi) => {\n const isActive = editor.isActive(name);\n editor.setFormat({ [name]: !isActive });\n return true;\n};\n\nconst simpleUploadHandler = async (config: {\n name: string;\n target: HTMLInputElement;\n uploader: (file: File, editor: SylApi) => Promise<any>;\n uploadBeforeInsert: boolean;\n editor: SylApi;\n getAttrs: (url: string, file: File) => Record<string, any>;\n}) => {\n const { name, target, uploader, getAttrs, uploadBeforeInsert, editor } = config;\n if (!target.files || !target.files.length) return;\n const file = target.files[0];\n let index = editor.getSelection().index;\n let url = '';\n if (!uploadBeforeInsert) {\n url = URL.createObjectURL(file);\n editor.insertCard(name, getAttrs(url, file), index);\n }\n const attrs = await uploader(file, editor);\n if (!uploadBeforeInsert) {\n index = -1;\n editor.getExistNodes(name).some(val => {\n if (val.node.attrs.src === url) {\n index = val.pos;\n editor.delete(val.pos, 1, { addToHistory: false });\n return true;\n }\n });\n }\n if (attrs && index > -1) {\n index > -1 && editor.insertCard(name, attrs as any, index);\n }\n url && URL.revokeObjectURL(url);\n};\n\nexport {\n addAttrsByConfig,\n checkMarkDisable,\n checkParentHaveAttr,\n checkParentSupportAttr,\n createFileInput,\n getFixSize,\n getFromDOMByConfig,\n getMarkDisable,\n isMatchObject,\n IUserAttrsConfig,\n keymapToggleMark,\n setAlign,\n setDOMAttrByConfig,\n simpleUploadHandler,\n};\n"]} |
+3
-3
| { | ||
| "name": "@syllepsis/plugin-basic", | ||
| "version": "0.1.55", | ||
| "version": "0.1.57", | ||
| "description": "basic plugins of syllepsis editor", | ||
@@ -39,3 +39,3 @@ "author": "wangmou <wangmou@bytedance.com>", | ||
| "dependencies": { | ||
| "@syllepsis/adapter": "^0.1.55", | ||
| "@syllepsis/adapter": "^0.1.57", | ||
| "@types/color": "^3.0.2", | ||
@@ -50,3 +50,3 @@ "@types/lodash.debounce": "^4.0.0", | ||
| }, | ||
| "gitHead": "911b9446f6b20a2efca8bb5f064744b0a01f4750" | ||
| "gitHead": "3fae3b690c5c3c5664dc860659ded9d1d74d9e08" | ||
| } |
@@ -119,3 +119,3 @@ import { BlockAtom, getPx, INodeInfo, SylApi, SylController, SylPlugin } from '@syllepsis/adapter'; | ||
| const pos = state.selection.from; | ||
| const $pos = state.doc.resolve(pos); | ||
| const imageType = state.schema.nodes?.image; | ||
@@ -125,6 +125,2 @@ const images = [...dataInfos]; | ||
| // when depth >= 2 and contained in table, inserting images will not update the selection,causes it to be inserted in reverse order | ||
| const isInTable = $pos.node(1)?.type?.name === 'table' && $pos.depth >= 2; | ||
| if (isInTable) { | ||
| images.reverse(); | ||
| } | ||
| images.forEach(({ image, attrs }) => { | ||
@@ -139,9 +135,5 @@ if (!image || !attrs) return; | ||
| }; | ||
| if (isInTable) { | ||
| editor.insert({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } else { | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| } | ||
| insertNodes.content.push({ type: PLUGIN_NAME, attrs: imageAttrs }); | ||
| }); | ||
| if (insertNodes.content.length && !isInTable) editor.insert(insertNodes, pos); | ||
| if (insertNodes.content.length) editor.insert(insertNodes, pos); | ||
| }; | ||
@@ -148,0 +140,0 @@ |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
@@ -17,3 +17,3 @@ declare module '@syllepsis/adapter' { | ||
| class AlignCenterPlugin extends SylPlugin { | ||
| class AlignCenterPlugin extends SylPlugin<IAlignProps> { | ||
| public name = 'align_center'; | ||
@@ -20,0 +20,0 @@ public Controller = AlignCenterController; |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
@@ -17,3 +17,3 @@ declare module '@syllepsis/adapter' { | ||
| class AlignJustifyPlugin extends SylPlugin { | ||
| class AlignJustifyPlugin extends SylPlugin<IAlignProps> { | ||
| public name = 'align_justify'; | ||
@@ -20,0 +20,0 @@ public Controller = AlignJustifyController; |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
@@ -16,3 +16,3 @@ declare module '@syllepsis/adapter' { | ||
| class AlignLeftPlugin extends SylPlugin { | ||
| class AlignLeftPlugin extends SylPlugin<IAlignProps> { | ||
| public name = 'align_left'; | ||
@@ -19,0 +19,0 @@ public Controller = AlignLeftController; |
| import { SylPlugin } from '@syllepsis/adapter'; | ||
| import { AlignController } from '../common'; | ||
| import { AlignController, IAlignProps } from '../common'; | ||
@@ -17,3 +17,3 @@ declare module '@syllepsis/adapter' { | ||
| class AlignRightPlugin extends SylPlugin { | ||
| class AlignRightPlugin extends SylPlugin<IAlignProps> { | ||
| public name = 'align_right'; | ||
@@ -20,0 +20,0 @@ public Controller = AlignRightController; |
@@ -6,3 +6,8 @@ import { SylApi, SylController } from '@syllepsis/adapter'; | ||
| class AlignController extends SylController { | ||
| interface IAlignProps { | ||
| /** includes all related nodes not just the top child node that supports `align` attributes */ | ||
| inclusive?: boolean; | ||
| } | ||
| class AlignController extends SylController<IAlignProps> { | ||
| public checkActive = true; | ||
@@ -12,3 +17,3 @@ public value: 'left' | 'right' | 'center' | 'justify' = 'left'; | ||
| public toolbar = { | ||
| handler: (editor: SylApi) => this.command.setStyle(editor) | ||
| handler: (editor: SylApi) => this.command.setStyle(editor), | ||
| }; | ||
@@ -18,11 +23,12 @@ | ||
| setStyle: (editor: SylApi) => { | ||
| setAlign(editor.view, this.value); | ||
| setAlign(editor.view, this.value, this.props.inclusive); | ||
| editor.focus(); | ||
| } | ||
| }, | ||
| }; | ||
| public disable = (editor: SylApi) => !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align'); | ||
| public disable = (editor: SylApi) => | ||
| !(editor.view.state.selection instanceof AllSelection) && !checkParentSupportAttr(editor.view, 'align'); | ||
| public active = () => (this.checkActive ? checkParentHaveAttr(this.editor.view, 'align', this.value) : false); | ||
| } | ||
| export { AlignController }; | ||
| export { AlignController, IAlignProps }; |
@@ -43,3 +43,3 @@ import { SylApi, Types } from '@syllepsis/adapter'; | ||
| const setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify') => { | ||
| const setAlign = (view: EditorView, align: 'left' | 'center' | 'right' | 'justify', inclusive = false) => { | ||
| const { state, dispatch } = view; | ||
@@ -53,5 +53,5 @@ const tr = state.tr; | ||
| state.doc.nodesBetween(from, to, (node, nodePos) => { | ||
| if (node.isTextblock || node.attrs.align !== undefined) { | ||
| if (node.attrs.align !== undefined) { | ||
| tr.setNodeMarkup(nodePos, undefined, { ...node.attrs, align }); | ||
| return false; | ||
| return inclusive; | ||
| } | ||
@@ -179,3 +179,2 @@ }); | ||
| export { | ||
@@ -195,3 +194,3 @@ addAttrsByConfig, | ||
| setDOMAttrByConfig, | ||
| simpleUploadHandler | ||
| simpleUploadHandler, | ||
| }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1438305
-0.1%19694
-0.08%Updated