@lvce-editor/preview-worker 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/previewWorkerMain.js +58 -0
- package/package.json +1 -1
|
@@ -90424,6 +90424,56 @@ const handleFileEdited = async state => {
|
|
|
90424
90424
|
};
|
|
90425
90425
|
};
|
|
90426
90426
|
|
|
90427
|
+
const dispatchInputEvent = (element, window) => {
|
|
90428
|
+
const inputEvent = new window.Event('input', {
|
|
90429
|
+
bubbles: true
|
|
90430
|
+
});
|
|
90431
|
+
dispatchEvent(element, inputEvent);
|
|
90432
|
+
};
|
|
90433
|
+
|
|
90434
|
+
const handleInput = (state, hdId, value) => {
|
|
90435
|
+
// console.log('input,', hdId, value)
|
|
90436
|
+
if (!hdId) {
|
|
90437
|
+
return state;
|
|
90438
|
+
}
|
|
90439
|
+
const happyDomInstance = get(state.uid);
|
|
90440
|
+
if (!happyDomInstance) {
|
|
90441
|
+
return state;
|
|
90442
|
+
}
|
|
90443
|
+
const element = happyDomInstance.elementMap.get(hdId);
|
|
90444
|
+
if (!element) {
|
|
90445
|
+
return state;
|
|
90446
|
+
}
|
|
90447
|
+
|
|
90448
|
+
// console.log({ element })
|
|
90449
|
+
// Update the element's value from the preview
|
|
90450
|
+
element.value = value;
|
|
90451
|
+
// Dispatch input event in happy-dom so event listeners fire
|
|
90452
|
+
dispatchInputEvent(element, happyDomInstance.window);
|
|
90453
|
+
|
|
90454
|
+
// Re-serialize the (potentially mutated) DOM
|
|
90455
|
+
const elementMap = new Map();
|
|
90456
|
+
const serialized = serialize(happyDomInstance.document, elementMap);
|
|
90457
|
+
|
|
90458
|
+
// Update happy-dom state with new element map
|
|
90459
|
+
set(state.uid, {
|
|
90460
|
+
document: happyDomInstance.document,
|
|
90461
|
+
elementMap,
|
|
90462
|
+
window: happyDomInstance.window
|
|
90463
|
+
});
|
|
90464
|
+
const parsedDom = serialized.dom;
|
|
90465
|
+
const {
|
|
90466
|
+
css
|
|
90467
|
+
} = serialized;
|
|
90468
|
+
const parsedNodesChildNodeCount = getParsedNodesChildNodeCount(parsedDom);
|
|
90469
|
+
return {
|
|
90470
|
+
...state,
|
|
90471
|
+
css,
|
|
90472
|
+
parsedDom,
|
|
90473
|
+
parsedNodesChildNodeCount
|
|
90474
|
+
};
|
|
90475
|
+
};
|
|
90476
|
+
|
|
90427
90477
|
const loadContent = async state => {
|
|
90428
90478
|
// Try to register to receive editor change notifications from the editor worker.
|
|
90429
90479
|
// Use dynamic access and ignore errors so this is safe in environments where
|
|
@@ -90511,6 +90561,7 @@ const renderCss = (oldState, newState) => {
|
|
|
90511
90561
|
return ['Viewlet.setCss', uid, cssString];
|
|
90512
90562
|
};
|
|
90513
90563
|
|
|
90564
|
+
const HandleInput = 4;
|
|
90514
90565
|
const HandleClick = 11;
|
|
90515
90566
|
|
|
90516
90567
|
const getEmptyPreviewDom = () => {
|
|
@@ -90543,6 +90594,7 @@ const getPreviewDom = state => {
|
|
|
90543
90594
|
childCount: parsedNodesChildNodeCount,
|
|
90544
90595
|
className: 'Viewlet Preview',
|
|
90545
90596
|
onClick: HandleClick,
|
|
90597
|
+
onInput: HandleInput,
|
|
90546
90598
|
type: Div$1
|
|
90547
90599
|
}, ...parsedDom];
|
|
90548
90600
|
}
|
|
@@ -90550,6 +90602,7 @@ const getPreviewDom = state => {
|
|
|
90550
90602
|
childCount: 1,
|
|
90551
90603
|
className: 'Viewlet Preview',
|
|
90552
90604
|
onClick: HandleClick,
|
|
90605
|
+
onInput: HandleInput,
|
|
90553
90606
|
type: Div$1
|
|
90554
90607
|
}, {
|
|
90555
90608
|
childCount: 1,
|
|
@@ -90619,6 +90672,10 @@ const renderEventListeners = () => {
|
|
|
90619
90672
|
capture: true,
|
|
90620
90673
|
name: HandleClick,
|
|
90621
90674
|
params: ['handleClick', 'event.target.dataset.id']
|
|
90675
|
+
}, {
|
|
90676
|
+
capture: true,
|
|
90677
|
+
name: HandleInput,
|
|
90678
|
+
params: ['handleInput', 'event.target.dataset.id', 'event.target.value']
|
|
90622
90679
|
}];
|
|
90623
90680
|
};
|
|
90624
90681
|
|
|
@@ -90675,6 +90732,7 @@ const commandMap = {
|
|
|
90675
90732
|
'Preview.getCommandIds': getCommandIds,
|
|
90676
90733
|
'Preview.handleClick': wrapCommand(handleClick),
|
|
90677
90734
|
'Preview.handleFileEdited': wrapCommand(handleFileEdited),
|
|
90735
|
+
'Preview.handleInput': wrapCommand(handleInput),
|
|
90678
90736
|
'Preview.loadContent': wrapCommand(loadContent),
|
|
90679
90737
|
'Preview.render2': render2,
|
|
90680
90738
|
'Preview.renderEventListeners': renderEventListeners,
|