add lexical-file package (#1286)

This commit is contained in:
Acy Watson
2022-02-14 10:31:19 -08:00
committed by acywatson
parent 4c3dfe677f
commit 44e8daeae4
12 changed files with 92 additions and 27 deletions

View File

@ -32,13 +32,13 @@ module.name_mapper='^lexical/OverflowNode' -> '<PROJECT_ROOT>/packages/lexical/s
module.name_mapper='^lexical/ExtendedNodes' -> '<PROJECT_ROOT>/packages/lexical/src/nodes/extended/LexicalExtendedNodes.js' module.name_mapper='^lexical/ExtendedNodes' -> '<PROJECT_ROOT>/packages/lexical/src/nodes/extended/LexicalExtendedNodes.js'
module.name_mapper='^@lexical/list' -> '<PROJECT_ROOT>/packages/lexical-list/src/index.js' module.name_mapper='^@lexical/list' -> '<PROJECT_ROOT>/packages/lexical-list/src/index.js'
module.name_mapper='^@lexical/file' -> '<PROJECT_ROOT>/packages/lexical-file/src/index.js'
module.name_mapper='^@lexical/helpers/selection' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalSelectionHelpers.js' module.name_mapper='^@lexical/helpers/selection' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalSelectionHelpers.js'
module.name_mapper='^@lexical/helpers/text' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalTextHelpers.js' module.name_mapper='^@lexical/helpers/text' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalTextHelpers.js'
module.name_mapper='^@lexical/helpers/nodes' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalNodeHelpers.js' module.name_mapper='^@lexical/helpers/nodes' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalNodeHelpers.js'
module.name_mapper='^@lexical/helpers/elements' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalElementHelpers.js' module.name_mapper='^@lexical/helpers/elements' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalElementHelpers.js'
module.name_mapper='^@lexical/helpers/events' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalEventHelpers.js' module.name_mapper='^@lexical/helpers/events' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalEventHelpers.js'
module.name_mapper='^@lexical/helpers/file' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalFileHelpers.js'
module.name_mapper='^@lexical/helpers/offsets' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalOffsetHelpers.js' module.name_mapper='^@lexical/helpers/offsets' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalOffsetHelpers.js'
module.name_mapper='^@lexical/helpers/root' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalRootHelpers.js' module.name_mapper='^@lexical/helpers/root' -> '<PROJECT_ROOT>/packages/lexical-helpers/src/LexicalRootHelpers.js'

View File

@ -21,12 +21,11 @@ module.exports = {
}, },
moduleNameMapper: { moduleNameMapper: {
'^./dist/(.+)': './src/$1', '^./dist/(.+)': './src/$1',
'^@lexical/file$': '<rootDir>/packages/lexical-file/src/index.js',
'^@lexical/helpers/elements$': '^@lexical/helpers/elements$':
'<rootDir>/packages/lexical-helpers/src/LexicalElementHelpers.js', '<rootDir>/packages/lexical-helpers/src/LexicalElementHelpers.js',
'^@lexical/helpers/events$': '^@lexical/helpers/events$':
'<rootDir>/packages/lexical-helpers/src/LexicalEventHelpers.js', '<rootDir>/packages/lexical-helpers/src/LexicalEventHelpers.js',
'^@lexical/helpers/file$':
'<rootDir>/packages/lexical-helpers/src/LexicalFileHelpers.js',
'^@lexical/helpers/nodes$': '^@lexical/helpers/nodes$':
'<rootDir>/packages/lexical-helpers/src/LexicalNodeHelpers.js', '<rootDir>/packages/lexical-helpers/src/LexicalNodeHelpers.js',
'^@lexical/helpers/offsets$': '^@lexical/helpers/offsets$':

17
package-lock.json generated
View File

@ -6873,6 +6873,10 @@
"node": ">= 10.14.2" "node": ">= 10.14.2"
} }
}, },
"node_modules/@lexical/file": {
"resolved": "packages/lexical-file",
"link": true
},
"node_modules/@lexical/helpers": { "node_modules/@lexical/helpers": {
"resolved": "packages/lexical-helpers", "resolved": "packages/lexical-helpers",
"link": true "link": true
@ -32530,6 +32534,14 @@
"version": "0.1.8", "version": "0.1.8",
"license": "MIT" "license": "MIT"
}, },
"packages/lexical-file": {
"name": "@lexical/file",
"version": "0.1.8",
"license": "MIT",
"peerDependencies": {
"lexical": "0.1.8"
}
},
"packages/lexical-helpers": { "packages/lexical-helpers": {
"name": "@lexical/helpers", "name": "@lexical/helpers",
"version": "0.1.8", "version": "0.1.8",
@ -32552,6 +32564,7 @@
"dependencies": { "dependencies": {
"@craco/craco": "6.1.2", "@craco/craco": "6.1.2",
"@excalidraw/excalidraw": "latest", "@excalidraw/excalidraw": "latest",
"@lexical/file": "0.1.8",
"@lexical/helpers": "0.1.8", "@lexical/helpers": "0.1.8",
"@lexical/list": "0.1.8", "@lexical/list": "0.1.8",
"@lexical/react": "0.1.8", "@lexical/react": "0.1.8",
@ -37019,6 +37032,9 @@
"chalk": "^4.0.0" "chalk": "^4.0.0"
} }
}, },
"@lexical/file": {
"version": "file:packages/lexical-file"
},
"@lexical/helpers": { "@lexical/helpers": {
"version": "file:packages/lexical-helpers" "version": "file:packages/lexical-helpers"
}, },
@ -45677,6 +45693,7 @@
"requires": { "requires": {
"@craco/craco": "6.1.2", "@craco/craco": "6.1.2",
"@excalidraw/excalidraw": "latest", "@excalidraw/excalidraw": "latest",
"@lexical/file": "0.1.8",
"@lexical/helpers": "0.1.8", "@lexical/helpers": "0.1.8",
"@lexical/list": "0.1.8", "@lexical/list": "0.1.8",
"@lexical/react": "0.1.8", "@lexical/react": "0.1.8",

View File

@ -0,0 +1,3 @@
'use strict';
module.exports = require('./dist/LexicalFile.js');

View File

@ -0,0 +1,3 @@
# `@lexical/file`
This package contains the functionality for the file import/export feature of Lexical.

View File

@ -0,0 +1,27 @@
{
"name": "@lexical/file",
"author": {
"name": "Dominic Gannaway",
"email": "dg@domgan.com"
},
"description": "This package provides the file import/export feature for Lexical.",
"keywords": [
"lexical",
"editor",
"rich-text",
"file",
"import",
"export"
],
"license": "MIT",
"version": "0.1.8",
"main": "LexicalFile.js",
"peerDependencies": {
"lexical": "0.1.8"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/lexical",
"directory": "packages/lexical-file"
}
}

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
*/
import {exportFile,importFile} from './fileImportExport';
export {exportFile,importFile};

View File

@ -10,6 +10,7 @@
"@lexical/react": "0.1.8", "@lexical/react": "0.1.8",
"@lexical/helpers": "0.1.8", "@lexical/helpers": "0.1.8",
"@lexical/list": "0.1.8", "@lexical/list": "0.1.8",
"@lexical/file": "0.1.8",
"link-preview-generator": "1.0.7", "link-preview-generator": "1.0.7",
"@craco/craco": "6.1.2", "@craco/craco": "6.1.2",
"@excalidraw/excalidraw": "latest", "@excalidraw/excalidraw": "latest",

View File

@ -16,7 +16,7 @@ import {useCallback, useEffect, useState} from 'react';
import {$createStickyNode} from '../nodes/StickyNode'; import {$createStickyNode} from '../nodes/StickyNode';
import {$log, $getRoot} from 'lexical'; import {$log, $getRoot} from 'lexical';
import {SUPPORT_SPEECH_RECOGNITION} from './SpeechToTextPlugin'; import {SUPPORT_SPEECH_RECOGNITION} from './SpeechToTextPlugin';
import {importFile, exportFile} from '@lexical/helpers/file'; import {importFile, exportFile} from '@lexical/file';
const EditorPriority: CommandListenerEditorPriority = 0; const EditorPriority: CommandListenerEditorPriority = 0;

View File

@ -43,10 +43,12 @@ if (isClean) {
fs.removeSync(path.resolve('./packages/lexical-react/dist')); fs.removeSync(path.resolve('./packages/lexical-react/dist'));
fs.removeSync(path.resolve('./packages/lexical-helpers/dist')); fs.removeSync(path.resolve('./packages/lexical-helpers/dist'));
fs.removeSync(path.resolve('./packages/lexical-list/dist')); fs.removeSync(path.resolve('./packages/lexical-list/dist'));
fs.removeSync(path.resolve('./packages/lexical-file/dist'));
fs.removeSync(path.resolve('./packages/lexical-yjs/dist')); fs.removeSync(path.resolve('./packages/lexical-yjs/dist'));
} }
const wwwMappings = { const wwwMappings = {
'@lexical/file': 'LexicalFile',
'@lexical/list': 'LexicalList', '@lexical/list': 'LexicalList',
'@lexical/yjs': 'LexicalYjs', '@lexical/yjs': 'LexicalYjs',
lexical: 'Lexical', lexical: 'Lexical',
@ -94,6 +96,7 @@ const externals = [
// is different to that of the OSS version). // is different to that of the OSS version).
'lexical', 'lexical',
'@lexical/list', '@lexical/list',
'@lexical/file',
'@lexical/yjs', '@lexical/yjs',
'react-dom', 'react-dom',
'react', 'react',
@ -181,12 +184,6 @@ async function build(name, inputFile, outputFile, isProd) {
'packages/lexical-helpers/src/LexicalEventHelpers', 'packages/lexical-helpers/src/LexicalEventHelpers',
), ),
}, },
{
find: '@lexical/helpers/file',
replacement: path.resolve(
'packages/lexical-helpers/src/LexicalFileHelpers',
),
},
{ {
find: '@lexical/helpers/offsets', find: '@lexical/helpers/offsets',
replacement: path.resolve( replacement: path.resolve(
@ -336,6 +333,17 @@ const packages = [
outputPath: './packages/lexical-list/dist/', outputPath: './packages/lexical-list/dist/',
sourcePath: './packages/lexical-list/src/', sourcePath: './packages/lexical-list/src/',
}, },
{
modules: [
{
outputFileName: 'LexicalFile',
sourceFileName: 'index.js',
},
],
name: 'Lexical File',
outputPath: './packages/lexical-file/dist/',
sourcePath: './packages/lexical-file/src/',
},
{ {
modules: lexicalNodes.map((module) => ({ modules: lexicalNodes.map((module) => ({
name: module, name: module,

View File

@ -67,9 +67,6 @@ async function prepareLexicalHelpersPackage() {
await exec( await exec(
`mv ./packages/lexical-helpers/npm/LexicalEventHelpers.js ./packages/lexical-helpers/npm/events.js`, `mv ./packages/lexical-helpers/npm/LexicalEventHelpers.js ./packages/lexical-helpers/npm/events.js`,
); );
await exec(
`mv ./packages/lexical-helpers/npm/LexicalFileHelpers.js ./packages/lexical-helpers/npm/file.js`,
);
await exec( await exec(
`mv ./packages/lexical-helpers/npm/LexicalOffsetHelpers.js ./packages/lexical-helpers/npm/offsets.js`, `mv ./packages/lexical-helpers/npm/LexicalOffsetHelpers.js ./packages/lexical-helpers/npm/offsets.js`,
); );
@ -122,23 +119,21 @@ async function prepareLexicalYjsPackage() {
); );
} }
async function prepareLexicalListPackage() { async function prepareLexicalFeaturePackages() {
await exec(`rm -rf ./packages/lexical-list/npm`); const packages = ['lexical-list', 'lexical-file'];
await exec(`mkdir ./packages/lexical-list/npm`); for (let i = 0; i < packages.length; i++) {
await exec( const pkg = packages[i];
`cp -R ./packages/lexical-list/dist/*.js ./packages/lexical-list/npm`, await exec(`rm -rf ./packages/${pkg}/npm`);
); await exec(`mkdir ./packages/${pkg}/npm`);
await exec( await exec(`cp -R ./packages/${pkg}/dist/*.js ./packages/${pkg}/npm`);
`cp -R ./packages/lexical-list/package.json ./packages/lexical-list/npm`, await exec(`cp -R ./packages/${pkg}/package.json ./packages/${pkg}/npm`);
); await exec(`cp -R LICENSE ./packages/${pkg}/npm`);
await exec(`cp -R LICENSE ./packages/lexical-list/npm`); await exec(`cp -R ./packages/${pkg}/README.md ./packages/${pkg}/npm`);
await exec( }
`cp -R ./packages/lexical-list/README.md ./packages/lexical-list/npm`,
);
} }
prepareLexicalCorePackage(); prepareLexicalCorePackage();
prepareLexicalHelpersPackage(); prepareLexicalHelpersPackage();
prepareLexicalReactPackage(); prepareLexicalReactPackage();
prepareLexicalYjsPackage(); prepareLexicalYjsPackage();
prepareLexicalListPackage(); prepareLexicalFeaturePackages();