Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into node-fork-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed Apr 1, 2024
2 parents 8685c5d + 111117d commit 09f56cb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/lexical-playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import react from '@vitejs/plugin-react';
import {defineConfig} from 'vite';
import {replaceCodePlugin} from 'vite-plugin-replace';

import viteCopyEsm from './viteCopyEsm';
import moduleResolution from './viteModuleResolution';

// https://vitejs.dev/config/
Expand Down Expand Up @@ -54,6 +55,7 @@ export default defineConfig({
presets: ['@babel/preset-react'],
}),
react(),
viteCopyEsm(),
],
resolve: {
alias: moduleResolution,
Expand Down
2 changes: 2 additions & 0 deletions packages/lexical-playground/vite.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import react from '@vitejs/plugin-react';
import {defineConfig} from 'vite';
import {replaceCodePlugin} from 'vite-plugin-replace';

import viteCopyEsm from './viteCopyEsm';
import moduleResolution from './viteModuleResolution';

// https://vitejs.dev/config/
Expand Down Expand Up @@ -53,6 +54,7 @@ export default defineConfig({
presets: ['@babel/preset-react'],
}),
react(),
viteCopyEsm(),
],
resolve: {
alias: moduleResolution,
Expand Down
41 changes: 41 additions & 0 deletions packages/lexical-playground/viteCopyEsm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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.
*
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
import copy from 'rollup-plugin-copy';

function parseImportMapImportEntries() {
const m = /<script type="importmap">([\s\S]+?)<\/script>/g.exec(
fs.readFileSync('./esm/index.html', 'utf8'),
);
if (!m) {
throw new Error('Could not parse importmap from esm/index.html');
}
return Object.entries<string>(JSON.parse(m[1]).imports);
}

// Fork modules are only produced by the build script
export default function viteCopyEsm() {
return copy({
hook: 'writeBundle',
targets: [
{dest: './build/esm/', src: './esm/*'},
{dest: './build/', src: ['./*.png', './*.ico']},
...parseImportMapImportEntries().map(([mod, fn]) => ({
dest: './build/esm/dist/',
src: path.join(
`../${mod.replace(/^@/, '').replace(/\//g, '-')}`,
// Fork modules are only produced by build-release, which is not run
// in CI, so we don't need to worry about choosing dev or prod
fn,
),
})),
],
verbose: true,
});
}
6 changes: 4 additions & 2 deletions packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,15 @@ export function $shouldInsertTextAfterOrBeforeTextNode(
if (offset === 0) {
return (
!node.canInsertTextBefore() ||
!parent.canInsertTextBefore() ||
(!parent.canInsertTextBefore() && !node.isComposing()) ||
isToken ||
$previousSiblingDoesNotAcceptText(node)
);
} else if (offset === node.getTextContentSize()) {
return (
!node.canInsertTextAfter() || !parent.canInsertTextAfter() || isToken
!node.canInsertTextAfter() ||
(!parent.canInsertTextAfter() && !node.isComposing()) ||
isToken
);
} else {
return false;
Expand Down

0 comments on commit 09f56cb

Please sign in to comment.