From 9dc6a98a6fd5aed1a8da5f3590d3cdc35b1d0d7f Mon Sep 17 00:00:00 2001 From: sibiraj-s Date: Sun, 24 Jan 2021 17:13:01 +0530 Subject: [PATCH] refactor: provide schema via secondary entrypoint --- src/lib/Editor.ts | 2 +- src/lib/schema.ts | 14 ++------------ src/schema/index.ts | 11 +++++++++++ src/{lib => }/schema/marks.ts | 4 ++-- src/{lib => }/schema/nodes.ts | 2 +- src/schema/package.json | 11 +++++++++++ src/schema/public_api.ts | 3 +++ src/{lib => }/utils/isNil.ts | 0 src/utils/package.json | 7 +++++++ src/utils/public_api.ts | 2 ++ src/{lib => }/utils/toStyleString.ts | 0 tsconfig.json | 24 ++++++++---------------- 12 files changed, 48 insertions(+), 32 deletions(-) create mode 100644 src/schema/index.ts rename src/{lib => }/schema/marks.ts (98%) rename src/{lib => }/schema/nodes.ts (99%) create mode 100644 src/schema/package.json create mode 100644 src/schema/public_api.ts rename src/{lib => }/utils/isNil.ts (100%) create mode 100644 src/utils/package.json create mode 100644 src/utils/public_api.ts rename src/{lib => }/utils/toStyleString.ts (100%) diff --git a/src/lib/Editor.ts b/src/lib/Editor.ts index 7d0fa304..0d00ae7a 100644 --- a/src/lib/Editor.ts +++ b/src/lib/Editor.ts @@ -7,11 +7,11 @@ import { editable as editablePlugin, placeholder as placeholderPlugin } from 'ngx-editor/plugins'; +import { isNil } from 'ngx-editor/utils'; import EditorCommands from './EditorCommands'; import defautlSchema from './schema'; import { parseContent } from './parsers'; -import isNil from './utils/isNil'; import getDefaultPlugins from './defaultPlugins'; type Content = string | Record | null; diff --git a/src/lib/schema.ts b/src/lib/schema.ts index b64ee6a0..1739afed 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -1,14 +1,4 @@ -import { Schema } from 'prosemirror-model'; - -import nodes from './schema/nodes'; -import marks from './schema/marks'; - -export { default as marks } from './schema/marks'; -export { default as nodes } from './schema/nodes'; - -export const schema = new Schema({ - marks, - nodes -}); +import { schema } from 'ngx-editor/schema'; +export { schema, marks, nodes } from 'ngx-editor/schema'; export default schema; diff --git a/src/schema/index.ts b/src/schema/index.ts new file mode 100644 index 00000000..74972dbb --- /dev/null +++ b/src/schema/index.ts @@ -0,0 +1,11 @@ +import { Schema } from 'prosemirror-model'; + +import marks from './marks'; +import nodes from './nodes'; + +const schema = new Schema({ + marks, + nodes +}); + +export default schema; diff --git a/src/lib/schema/marks.ts b/src/schema/marks.ts similarity index 98% rename from src/lib/schema/marks.ts rename to src/schema/marks.ts index 5a7efa92..4011313d 100644 --- a/src/lib/schema/marks.ts +++ b/src/schema/marks.ts @@ -141,7 +141,7 @@ const textBackgroundColor: MarkSpec = { }, }; -const makrs = { +const marks = { link, em, strong, @@ -152,4 +152,4 @@ const makrs = { text_background_color: textBackgroundColor }; -export default makrs; +export default marks; diff --git a/src/lib/schema/nodes.ts b/src/schema/nodes.ts similarity index 99% rename from src/lib/schema/nodes.ts rename to src/schema/nodes.ts index 2b5efc05..f5f3a69d 100644 --- a/src/lib/schema/nodes.ts +++ b/src/schema/nodes.ts @@ -1,7 +1,7 @@ import { DOMOutputSpec, Node as ProsemirrorNode, NodeSpec } from 'prosemirror-model'; import * as sl from 'prosemirror-schema-list'; -import toStyleString from '../utils/toStyleString'; +import { toStyleString } from 'ngx-editor/utils'; const doc: NodeSpec = { content: 'block+' diff --git a/src/schema/package.json b/src/schema/package.json new file mode 100644 index 00000000..0c88ea31 --- /dev/null +++ b/src/schema/package.json @@ -0,0 +1,11 @@ +{ + "ngPackage": { + "lib": { + "entryFile": "./public_api.ts", + "umdModuleIds": { + "prosemirror-model": "prosemirrorModel", + "prosemirror-schema-list": "prosemirrorSchemaList" + } + } + } +} diff --git a/src/schema/public_api.ts b/src/schema/public_api.ts new file mode 100644 index 00000000..8d370850 --- /dev/null +++ b/src/schema/public_api.ts @@ -0,0 +1,3 @@ +export { default as marks } from './marks'; +export { default as nodes } from './nodes'; +export { default as schema } from './index'; diff --git a/src/lib/utils/isNil.ts b/src/utils/isNil.ts similarity index 100% rename from src/lib/utils/isNil.ts rename to src/utils/isNil.ts diff --git a/src/utils/package.json b/src/utils/package.json new file mode 100644 index 00000000..b118da5e --- /dev/null +++ b/src/utils/package.json @@ -0,0 +1,7 @@ +{ + "ngPackage": { + "lib": { + "entryFile": "./public_api.ts" + } + } +} diff --git a/src/utils/public_api.ts b/src/utils/public_api.ts new file mode 100644 index 00000000..ab59d1a6 --- /dev/null +++ b/src/utils/public_api.ts @@ -0,0 +1,2 @@ +export { default as isNil } from './isNil'; +export { default as toStyleString } from './toStyleString'; diff --git a/src/lib/utils/toStyleString.ts b/src/utils/toStyleString.ts similarity index 100% rename from src/lib/utils/toStyleString.ts rename to src/utils/toStyleString.ts diff --git a/tsconfig.json b/tsconfig.json index b1598a9b..a3b1ddc3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,33 +24,25 @@ "dist/ngx-editor/ngx-editor", "dist/ngx-editor" ], + "ngx-editor/utils": [ + "dist/ngx-editor/ngx-editor/utils", + "dist/ngx-editor/utils" + ], "ngx-editor/helpers": [ "dist/ngx-editor/ngx-editor/helpers", "dist/ngx-editor/helpers" ], + "ngx-editor/schema": [ + "dist/ngx-editor/ngx-editor/schema", + "dist/ngx-editor/schema" + ], "ngx-editor/commands": [ "dist/ngx-editor/ngx-editor/commands", "dist/ngx-editor/commands" ], - "ngx-editor/history": [ - "dist/ngx-editor/ngx-editor/history", - "dist/ngx-editor/history" - ], "ngx-editor/plugins": [ "dist/ngx-editor/ngx-editor/plugins", "dist/ngx-editor/plugins" - ], - "ngx-editor/keymap": [ - "dist/ngx-editor/ngx-editor/keymap", - "dist/ngx-editor/keymap" - ], - "ngx-editor/inputrules": [ - "dist/ngx-editor/ngx-editor/inputrules", - "dist/ngx-editor/inputrules" - ], - "ngx-editor/schema-list": [ - "dist/ngx-editor/ngx-editor/schema-list", - "dist/ngx-editor/schema-list" ] } },