Skip to content

Commit f9c8a20

Browse files
committed
Merge branch 'main' into next
2 parents e02da22 + 8c76c2d commit f9c8a20

File tree

11 files changed

+147
-8
lines changed

11 files changed

+147
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## editors
22
/.idea
3+
/.vscode
4+
/.history
35

46
## system files
57
.DS_Store

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"devDependencies": {
5454
"@changesets/cli": "^2.20.0",
5555
"@custom-elements-manifest/analyzer": "^0.4.12",
56-
"@open-wc/testing": "^3.0.0",
5756
"@playwright/test": "^1.18.1",
57+
"@open-wc/testing": "^3.1.2",
5858
"@rollup/plugin-commonjs": "^17.0.0",
5959
"@rollup/plugin-json": "^4.1.0",
6060
"@rollup/plugin-typescript": "^8.1.0",

packages/drawer/src/RocketDrawer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function transitionend(el) {
1313
});
1414
}
1515

16+
// @ts-expect-error
1617
export class RocketDrawer extends OverlayMixin(LitElement) {
1718
static get properties() {
1819
return {

packages/mdjs-preview/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @mdjs/mdjs-preview
22

3+
## 0.5.7
4+
5+
### Patch Changes
6+
7+
- f4d83fe: add overridable `renderFunction` to mdjs-preview
8+
39
## 0.5.6
410

511
### Patch Changes

packages/mdjs-preview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mdjs/mdjs-preview",
3-
"version": "0.5.6",
3+
"version": "0.5.7",
44
"publishConfig": {
55
"access": "public"
66
},

packages/mdjs-preview/src/MdJsPreview.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ import {
1010
} from './mdjsViewerSharedStates.js';
1111
import { addResizeHandler } from './resizeHandler.js';
1212

13+
/**
14+
* @typedef {{values: unknown[], strings:string[],processor:Function}} TemplateResult1
15+
* @typedef {import('lit').TemplateResult} TemplateResult2
16+
* @typedef {{templateFactory:any; eventContext: EventTarget }} RenderOptions1
17+
* @typedef {import('lit').RenderOptions} RenderOptions2
18+
*/
19+
1320
/**
1421
* @param {string} input
1522
* @param {'js'|'css'} type
@@ -72,6 +79,46 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
7279
};
7380
}
7481

82+
/**
83+
* By default, the render of lit2 is provided, which is compatible with TemplateResults of lit2.
84+
* However, in contexts that need to run multiple versions of lit, it should be possible to
85+
* provide a specific render function, like renderHybrid, that internally checks, based on the
86+
* TemplateResult, whether the render function of lit 1 or 2 should called.
87+
* Overriding the render function would look like:
88+
*
89+
* @protected
90+
* @param {TemplateResult1|TemplateResult2|LitHtmlStoryFn} html Any value renderable by NodePart - typically a TemplateResult
91+
* created by evaluating a template tag like `html` or `svg`.
92+
* @param {HTMLElement} container A DOM parent to render to. The entire contents are either
93+
* replaced, or efficiently updated if the same result type was previous
94+
* rendered there.
95+
* @param {Partial<RenderOptions2>} [options] RenderOptions for the entire render tree rendered to this
96+
* container. Render options must *not* change between renders to the same
97+
* container, as those changes will not effect previously rendered DOM.
98+
*
99+
* @example
100+
* ```js
101+
* import { MdJsPreview } from '@mdjs/mdjs-preview';
102+
* import { render as render2 } from 'lit';
103+
* import { isTemplateResult as isTemplateResult2 } from 'lit/directive-helpers.js';
104+
* import { render as render1 } from 'lit-html';
105+
*
106+
* export class HybridLitMdjsPreview extends MdJsPreview {
107+
* renderStory(html, container, options) {
108+
* if (isTemplateResult2(html)) {
109+
* render2(html, container, options);
110+
* } else {
111+
* render1(html, container, options);
112+
* }
113+
* }
114+
* }
115+
* customElements.define('mdjs-preview', HybridLitMdjsPreview);
116+
* ```
117+
*/
118+
renderStory(html, container, options) {
119+
render(html, container, options);
120+
}
121+
75122
constructor() {
76123
super();
77124
/** @type {LitHtmlStoryFn} */
@@ -257,7 +304,10 @@ export class MdJsPreview extends ScopedElementsMixin(LitElement) {
257304
}
258305

259306
if (this.lightDomRenderTarget && changeProps.has('story')) {
260-
render(this.story({ shadowRoot: this }), this.lightDomRenderTarget);
307+
this.renderStory(
308+
/** @type {LitHtmlStoryFn} */ (this.story({ shadowRoot: this })),
309+
this.lightDomRenderTarget,
310+
);
261311
}
262312

263313
if (changeProps.has('platform') || changeProps.has('size')) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, fixture, html } from '@open-wc/testing';
2+
import { html as storyHtml } from '@mdjs/mdjs-preview';
3+
import { MdJsPreview } from '@mdjs/mdjs-preview';
4+
import { render as render2 } from 'lit';
5+
import { isTemplateResult as isTemplateResult2 } from 'lit/directive-helpers.js';
6+
7+
/** @typedef {import('@mdjs/mdjs-preview').MdJsPreview} MdJsPreview */
8+
9+
describe('mdjs-preview Subclasser', () => {
10+
it('will expose a render function getter to override in extensions', async () => {
11+
let isCalled = false;
12+
class HybridLitMdjsPreview extends MdJsPreview {
13+
renderStory(html, container, options) {
14+
isCalled = true;
15+
if (isTemplateResult2(html)) {
16+
render2(html, container, options);
17+
} else {
18+
throw new Error('[mdjs-preview]: Only lit2 allowed');
19+
}
20+
}
21+
}
22+
customElements.define('mdjs-preview', HybridLitMdjsPreview);
23+
24+
const el = await fixture(html`
25+
<mdjs-preview .story=${() => storyHtml`<p id="testing"></p>`}></mdjs-preview>
26+
`);
27+
expect(isCalled).to.be.true;
28+
expect(el.querySelectorAll('#testing').length).to.equal(1);
29+
});
30+
});

packages/mdjs-preview/test-web/mdjs-preview.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '@mdjs/mdjs-preview/define';
55
/** @typedef {import('@mdjs/mdjs-preview').MdJsPreview} MdJsPreview */
66

77
describe('mdjs-preview', () => {
8-
it('will render the element into the shadow root by default', async () => {
8+
it('will render the element into light dom by default', async () => {
99
const el = await fixture(html`
1010
<mdjs-preview .story=${() => storyHtml`<p id="testing"></p>`}></mdjs-preview>
1111
`);

packages/search/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @rocket/search
22

3+
## 0.6.0
4+
5+
### Minor Changes
6+
7+
- c2c9ecd: Update @lion dependencies
8+
39
## 0.5.1
410

511
### Patch Changes

site/pages/30--tools/20--markdown-javascript/20--preview.rocket.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,28 @@ class DemoElement extends HTMLElement {
253253

254254
customElements.define('demo-element', DemoElement);
255255
```
256+
257+
## Extending mdjs-preview
258+
259+
It is possible to define a custom version of mdjs-preview in order to add functionality, change
260+
its appearance of make it run in 'hybrid mode' (accepting both lit1 and -2 TemplateResults).
261+
The example below shows how the latter can be achieved by providing a custom render function.
262+
Note that we define `mdjs-preview` as the custom element name. We need to make sure that this
263+
file is executed before the original mdjs-preview definition file is executed.
264+
265+
```js
266+
import { MdJsPreview } from '@mdjs/mdjs-preview';
267+
import { render as render2 } from 'lit';
268+
import { isTemplateResult as isTemplateResult2 } from 'lit/directive-helpers.js';
269+
import { render as render1 } from 'lit-html';
270+
271+
export class HybridLitMdjsPreview extends MdJsPreview {
272+
renderStory(html, container, options) {
273+
if (isTemplateResult2(html)) {
274+
render2(html, container, options);
275+
} else {
276+
render1(html, container, options);
277+
}
278+
}
279+
customElements.define('mdjs-preview', HybridLitMdjsPreview);
280+
```

yarn.lock

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,12 @@
15441544
parse5 "^6.0.1"
15451545
resolve "^1.10.1"
15461546

1547-
"@lit/reactive-element@^1.0.0", "@lit/reactive-element@^1.1.0", "@lit/reactive-element@^1.3.0":
1547+
"@lit/reactive-element@^1.0.0":
1548+
version "1.0.2"
1549+
resolved "https://registry.yarnpkg.com/@lit/reactive-element/-/reactive-element-1.0.2.tgz#daa7a7c7a6c63d735f0c9634de6b7dbd70a702ab"
1550+
integrity sha512-oz3d3MKjQ2tXynQgyaQaMpGTDNyNDeBdo6dXf1AbjTwhA1IRINHmA7kSaVYv9ttKweNkEoNqp9DqteDdgWzPEg==
1551+
1552+
"@lit/reactive-element@^1.1.0", "@lit/reactive-element@^1.3.0":
15481553
version "1.3.4"
15491554
resolved "https://registry.yarnpkg.com/@lit/reactive-element/-/reactive-element-1.3.4.tgz#c4492a54387f7b1020d498a348403229583d1c06"
15501555
integrity sha512-I1wz4uxOA52zSBhKmv4KQWLJpCyvfpnDg+eQR6mjpRgV+Ldi14HLPpSUpJklZRldz0fFmGCC/kVmuc/3cPFqCg==
@@ -1635,7 +1640,7 @@
16351640
lit "^2.0.0"
16361641
lit-html "^2.0.0"
16371642

1638-
"@open-wc/testing@^3.0.0":
1643+
"@open-wc/testing@^3.1.2":
16391644
version "3.1.3"
16401645
resolved "https://registry.yarnpkg.com/@open-wc/testing/-/testing-3.1.3.tgz#df569a7654bf42ff156b4a498e93789d82b56fdb"
16411646
integrity sha512-7JXMVs02IqY/lhvBoc++MT9sVPQOVjFP9sapCtHz9PCDO3TGAVj1122eNyhhCiHsuG89wdk21GQILfAozfSeMA==
@@ -2590,6 +2595,11 @@
25902595
portfinder "^1.0.28"
25912596
source-map "^0.7.3"
25922597

2598+
"@webcomponents/scoped-custom-element-registry@^0.0.3":
2599+
version "0.0.3"
2600+
resolved "https://registry.yarnpkg.com/@webcomponents/scoped-custom-element-registry/-/scoped-custom-element-registry-0.0.3.tgz#774591a886b0b0e4914717273ba53fd8d5657522"
2601+
integrity sha512-lpSzgDCGbM99dytb3+J3Suo4+Bk1E13MPnWB42JK8GwxSAxFz+tC7TTv2hhDSIE2IirGNKNKCf3m08ecu6eAsQ==
2602+
25932603
"@webcomponents/shadycss@^1.11.0":
25942604
version "1.11.0"
25952605
resolved "https://registry.yarnpkg.com/@webcomponents/shadycss/-/shadycss-1.11.0.tgz#73e289996c002d8be694cd3be0e83c46ad25e7e0"
@@ -5631,7 +5641,7 @@ lit-element@^2.0.1:
56315641
dependencies:
56325642
lit-html "^1.1.1"
56335643

5634-
lit-element@^3.1.0, lit-element@^3.2.0:
5644+
lit-element@^3.0.0, lit-element@^3.1.0, lit-element@^3.2.0:
56355645
version "3.2.2"
56365646
resolved "https://registry.yarnpkg.com/lit-element/-/lit-element-3.2.2.tgz#d148ab6bf4c53a33f707a5168e087725499e5f2b"
56375647
integrity sha512-6ZgxBR9KNroqKb6+htkyBwD90XGRiqKDHVrW/Eh0EZ+l+iC+u+v+w3/BA5NGi4nizAVHGYvQBHUDuSmLjPp7NQ==
@@ -5651,7 +5661,16 @@ lit-html@^2.0.0, lit-html@^2.1.0, lit-html@^2.2.0:
56515661
dependencies:
56525662
"@types/trusted-types" "^2.0.2"
56535663

5654-
lit@^2.0.0, lit@^2.0.2, lit@^2.1.0, lit@^2.2.5:
5664+
lit@^2.0.0, lit@^2.0.2:
5665+
version "2.0.2"
5666+
resolved "https://registry.yarnpkg.com/lit/-/lit-2.0.2.tgz#5e6f422924e0732258629fb379556b6d23f7179c"
5667+
integrity sha512-hKA/1YaSB+P+DvKWuR2q1Xzy/iayhNrJ3aveD0OQ9CKn6wUjsdnF/7LavDOJsKP/K5jzW/kXsuduPgRvTFrFJw==
5668+
dependencies:
5669+
"@lit/reactive-element" "^1.0.0"
5670+
lit-element "^3.0.0"
5671+
lit-html "^2.0.0"
5672+
5673+
lit@^2.1.0, lit@^2.2.5:
56555674
version "2.2.8"
56565675
resolved "https://registry.yarnpkg.com/lit/-/lit-2.2.8.tgz#26bdf560042aa3ec9b788f5d48119f7138b2dcc1"
56575676
integrity sha512-QjeNbi/H9LVIHR+u0OqsL+hs62a16m02JlJHYN48HcBuXyiPYR8JvzsTp5dYYS81l+b9Emp3UaGo82EheV0pog==

0 commit comments

Comments
 (0)