Compare commits

..

21 Commits

Author SHA1 Message Date
github-actions[bot]
d08692c7f3 Version Packages 2021-04-29 12:35:04 +02:00
Thomas Allmer
2b7f1ee719 fix: support pathprefix in cli, launch, mdjs, search 2021-04-29 12:30:47 +02:00
github-actions[bot]
3802778be4 Version Packages 2021-04-29 08:30:57 +02:00
Thomas Allmer
26f4a1ebff chore: align versions 2021-04-29 00:35:26 +02:00
Thomas Allmer
81edf45fe2 fix: drastically reduce the amount of js files in build output 2021-04-29 00:35:26 +02:00
github-actions[bot]
c5a1d7e8d1 Version Packages 2021-04-24 17:12:15 +02:00
Thomas Allmer
74dd8d1bcc fix(mdjs-preview): autoheight will not grow bigger than the current size height 2021-04-24 17:05:20 +02:00
Thomas Allmer
72f631ac86 chore: add releases 2021-04-23 13:06:44 +02:00
Thomas Allmer
fafb99b0fa feat(mdjs-preview): add a copy code button 2021-04-23 13:06:44 +02:00
Thomas Allmer
f5769b9aa9 fix(mdjs-preview): improve customization capabilities 2021-04-23 13:06:44 +02:00
Konstantinos Norgias
12d9cc3b44 fix: configure simulator themes & platforms 2021-04-23 11:37:34 +02:00
Konstantinos Norgias
ef9b373aa1 style: add color theming with css custom props 2021-04-23 11:37:34 +02:00
Konstantinos Norgias
560234d663 fix: default no render empty themes and platforms 2021-04-23 11:37:34 +02:00
Konstantinos Norgias
024514e901 style: add simulator css vars 2021-04-23 11:37:34 +02:00
Mathieu Puech
66c2d781e6 fix: windows path issue when using rocket lint 2021-04-23 11:18:53 +02:00
github-actions[bot]
14721d1e0f Version Packages 2021-04-20 12:58:41 +02:00
Thomas Allmer
0f6709ac4b fix(mdjs-preview): initial setting should come from the element 2021-04-20 12:55:32 +02:00
Thomas Allmer
ed86ff2346 fix(cli): do not set data-localize-lang in the simulator iframe html tag 2021-04-20 12:55:32 +02:00
Mathieu Puech
c675820163 fix: windows path issue avoid filtering of index section of collections 2021-04-20 12:28:19 +02:00
Konstantinos Norgias
f4a0ab559f fix: add changeset & update drawer 2021-04-20 12:27:12 +02:00
Konstantinos Norgias
a8cdaebab1 fix(simulator): document shadowRoot n/a in iframe 2021-04-20 12:27:12 +02:00
29 changed files with 316 additions and 132 deletions

View File

@@ -5,7 +5,7 @@ For that reason Rocket creates those automatically with the title, parent title,
It will look like this but with your logo: It will look like this but with your logo:
<img src="{{ socialMediaImage }}" width="1200" height="630" alt="Social Media Image of this page" style="border: 1px solid #000" /> <img src="{{ socialMediaImage | url }}" width="1200" height="630" alt="Social Media Image of this page" style="border: 1px solid #000" />
There are multiple ways you can modify it. There are multiple ways you can modify it.

View File

@@ -1,5 +1,11 @@
# check-html-links # check-html-links
## 0.2.2
### Patch Changes
- 66c2d78: fix: windows path issue
## 0.2.1 ## 0.2.1
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "check-html-links", "name": "check-html-links",
"version": "0.2.1", "version": "0.2.2",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },

View File

@@ -6,6 +6,7 @@ import { createRequire } from 'module';
import { listFiles } from './listFiles.js'; import { listFiles } from './listFiles.js';
import path from 'path'; import path from 'path';
import slash from 'slash';
/** @typedef {import('../types/main').Link} Link */ /** @typedef {import('../types/main').Link} Link */
/** @typedef {import('../types/main').LocalFile} LocalFile */ /** @typedef {import('../types/main').LocalFile} LocalFile */
@@ -45,7 +46,7 @@ function extractReferences(htmlFilePath) {
if (ev === SaxEventType.Attribute) { if (ev === SaxEventType.Attribute) {
const data = /** @type {Attribute} */ (/** @type {any} */ (_data)); const data = /** @type {Attribute} */ (/** @type {any} */ (_data));
const attributeName = data.name.toString(); const attributeName = data.name.toString();
const value = data.value.toString(); const value = slash(data.value.toString());
const entry = { const entry = {
attribute: attributeName, attribute: attributeName,
value, value,

View File

@@ -1,5 +1,21 @@
# @rocket/cli # @rocket/cli
## 0.6.3
### Patch Changes
- 2b7f1ee: Add support for pathprefix
- Updated dependencies [2b7f1ee]
- @rocket/eleventy-plugin-mdjs-unified@0.4.1
## 0.6.2
### Patch Changes
- ed86ff2: Do not set `data-localize-lang` in the simulator iframe html tag
- f4a0ab5: Pass document shadowRoot to iframe
- c675820: fix: windows path issue avoid filtering of index section of collections
## 0.6.1 ## 0.6.1
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@rocket/cli", "name": "@rocket/cli",
"version": "0.6.1", "version": "0.6.3",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
@@ -59,7 +59,7 @@
"@11ty/eleventy-img": "^0.7.4", "@11ty/eleventy-img": "^0.7.4",
"@rocket/building-rollup": "^0.2.0", "@rocket/building-rollup": "^0.2.0",
"@rocket/core": "^0.1.2", "@rocket/core": "^0.1.2",
"@rocket/eleventy-plugin-mdjs-unified": "^0.4.0", "@rocket/eleventy-plugin-mdjs-unified": "^0.4.1",
"@rocket/eleventy-rocket-nav": "^0.3.0", "@rocket/eleventy-rocket-nav": "^0.3.0",
"@rollup/plugin-babel": "^5.2.2", "@rollup/plugin-babel": "^5.2.2",
"@rollup/plugin-node-resolve": "^11.0.1", "@rollup/plugin-node-resolve": "^11.0.1",
@@ -67,12 +67,13 @@
"@web/dev-server": "^0.1.4", "@web/dev-server": "^0.1.4",
"@web/dev-server-rollup": "^0.3.2", "@web/dev-server-rollup": "^0.3.2",
"@web/rollup-plugin-copy": "^0.2.0", "@web/rollup-plugin-copy": "^0.2.0",
"check-html-links": "^0.2.1", "check-html-links": "^0.2.2",
"command-line-args": "^5.1.1", "command-line-args": "^5.1.1",
"command-line-usage": "^6.1.1", "command-line-usage": "^6.1.1",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"micromatch": "^4.0.2", "micromatch": "^4.0.2",
"plugins-manager": "^0.2.1", "plugins-manager": "^0.2.1",
"slash": "^3.0.0",
"utf8": "^3.0.0" "utf8": "^3.0.0"
}, },
"types": "dist-types/index.d.ts" "types": "dist-types/index.d.ts"

View File

@@ -1,7 +1,7 @@
<meta property="og:site_name" content="{{ site.name }}"/> <meta property="og:site_name" content="{{ site.name }}"/>
<meta property="og:type" content="website"/> <meta property="og:type" content="website"/>
<meta property="og:image" content="{{ socialMediaImage }}"/> <meta property="og:image" content="{{ socialMediaImage | url }}"/>
<meta property="og:url" content="{{ page.url }}"/> <meta property="og:url" content="{{ page.url | url }}"/>
<meta name="twitter:card" content="summary_large_image"/> <meta name="twitter:card" content="summary_large_image"/>

View File

@@ -35,7 +35,6 @@
if (urlParts.get('language')) { if (urlParts.get('language')) {
document.documentElement.setAttribute('lang', urlParts.get('language')); document.documentElement.setAttribute('lang', urlParts.get('language'));
document.documentElement.setAttribute('data-lang', urlParts.get('language')); document.documentElement.setAttribute('data-lang', urlParts.get('language'));
document.documentElement.setAttribute('data-localize-lang', urlParts.get('language'));
} }
if (urlParts.get('story-key')) { if (urlParts.get('story-key')) {
document.documentElement.setAttribute('story-key', urlParts.get('story-key')); document.documentElement.setAttribute('story-key', urlParts.get('story-key'));
@@ -47,7 +46,7 @@
} }
const mod = await import(urlParts.get('story-file')); const mod = await import(urlParts.get('story-file'));
render(mod[urlParts.get('story-key')](), document.body); render(mod[urlParts.get('story-key')]({ shadowRoot: document }), document.body);
} }
window.addEventListener('hashchange', onHashChange, false); window.addEventListener('hashchange', onHashChange, false);

View File

@@ -1,5 +1,6 @@
const path = require('path'); const path = require('path');
const fs = require('fs'); const fs = require('fs');
const slash = require('slash');
const { readdirSync } = require('fs'); const { readdirSync } = require('fs');
function getDirectories(source) { function getDirectories(source) {
@@ -23,7 +24,7 @@ const rocketCollections = {
let docs = [ let docs = [
...collection.getFilteredByGlob(`${_inputDirCwdRelative}/${section}/**/*.md`), ...collection.getFilteredByGlob(`${_inputDirCwdRelative}/${section}/**/*.md`),
]; ];
docs = docs.filter(page => page.inputPath !== `./${indexSection}`); docs = docs.filter(page => page.inputPath !== `./${slash(indexSection)}`);
return docs; return docs;
}); });

View File

@@ -1,5 +1,13 @@
# @rocket/eleventy-plugin-mdjs-unified # @rocket/eleventy-plugin-mdjs-unified
## 0.4.1
### Patch Changes
- 2b7f1ee: Add support for pathprefix
- Updated dependencies [2b7f1ee]
- @mdjs/core@0.7.1
## 0.4.0 ## 0.4.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@rocket/eleventy-plugin-mdjs-unified", "name": "@rocket/eleventy-plugin-mdjs-unified",
"version": "0.4.0", "version": "0.4.1",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
@@ -31,7 +31,7 @@
"mdjs" "mdjs"
], ],
"dependencies": { "dependencies": {
"@mdjs/core": "^0.7.0", "@mdjs/core": "^0.7.1",
"es-module-lexer": "^0.3.26", "es-module-lexer": "^0.3.26",
"unist-util-visit": "^2.0.3" "unist-util-visit": "^2.0.3"
}, },

View File

@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */ /* eslint-disable @typescript-eslint/ban-ts-comment */
const path = require('path'); const path = require('path');
const slash = require('slash');
const fs = require('fs'); const fs = require('fs');
const { mdjsProcess } = require('@mdjs/core'); const { mdjsProcess } = require('@mdjs/core');
const visit = require('unist-util-visit'); const visit = require('unist-util-visit');
@@ -121,8 +122,12 @@ function eleventyUnified(pluginOptions) {
return plugins.map(plugin => { return plugins.map(plugin => {
if (plugin.options) { if (plugin.options) {
plugin.options.page = eleventySettings.page; plugin.options.page = eleventySettings.page;
plugin.options.rocketConfig = eleventySettings.rocketConfig;
} else { } else {
plugin.options = { page: eleventySettings.page }; plugin.options = {
page: eleventySettings.page,
rocketConfig: eleventySettings.rocketConfig,
};
} }
return plugin; return plugin;
}); });
@@ -145,8 +150,19 @@ function eleventyUnified(pluginOptions) {
const newName = path.join(newFolder, '__mdjs-stories.js'); const newName = path.join(newFolder, '__mdjs-stories.js');
await fs.promises.mkdir(newFolder, { recursive: true }); await fs.promises.mkdir(newFolder, { recursive: true });
await fs.promises.writeFile(newName, result.jsCode, 'utf8'); await fs.promises.writeFile(newName, result.jsCode, 'utf8');
let scriptUrl = eleventySettings.page.url;
if (
eleventySettings.rocketConfig &&
eleventySettings.rocketConfig.command === 'build' &&
eleventySettings.rocketConfig.pathPrefix
) {
scriptUrl = slash(
path.join(eleventySettings.rocketConfig.pathPrefix, eleventySettings.page.url),
);
}
code += ` code += `
<script type="module" src="${eleventySettings.page.url}__mdjs-stories.js" mdjs-setup></script> <script type="module" src="${scriptUrl}__mdjs-stories.js" mdjs-setup></script>
`; `;
} }
return code; return code;

View File

@@ -1,5 +1,17 @@
# @rocket/launch # @rocket/launch
## 0.4.2
### Patch Changes
- 2b7f1ee: Add support for pathprefix
## 0.4.1
### Patch Changes
- 81edf45: Reduce the amount of js files in the build by avoiding inline script tags
## 0.4.0 ## 0.4.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@rocket/launch", "name": "@rocket/launch",
"version": "0.4.0", "version": "0.4.2",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
@@ -35,7 +35,7 @@
"preset" "preset"
], ],
"dependencies": { "dependencies": {
"@rocket/drawer": "^0.1.2", "@rocket/drawer": "^0.1.3",
"@rocket/navigation": "^0.2.1" "@rocket/navigation": "^0.2.1"
} }
} }

View File

@@ -1,17 +1 @@
{# <script type="module" src="{{ '/_assets/scripts/init-navigation.js' | asset | url }}"></script>
src leads to the file not being included/executed? bug in rollup-plugin-html?
<script type="module" src="{{ '/_assets/scripts/init-navigation.js' | asset }}"></script>
#}
<script type="module">
import '@rocket/navigation/rocket-navigation.js';
import '@rocket/drawer/rocket-drawer.js';
const drawer = document.querySelector('#sidebar');
// Toggle button
const triggers = document.querySelectorAll('[data-action="trigger-mobile-menu"]');
for (const trigger of [...triggers]) {
trigger.addEventListener('click', function () {
drawer.opened = true;
});
}
</script>

View File

@@ -1,7 +1,7 @@
<meta property="og:site_name" content="{{ site.name }}"/> <meta property="og:site_name" content="{{ site.name }}"/>
<meta property="og:type" content="website"/> <meta property="og:type" content="website"/>
<meta property="og:image" content="{{ socialMediaImage }}"/> <meta property="og:image" content="{{ socialMediaImage | url }}"/>
<meta property="og:url" content="{{ page.url }}"/> <meta property="og:url" content="{{ page.url | url }}"/>
<meta name="twitter:card" content="summary_large_image"/> <meta name="twitter:card" content="summary_large_image"/>

View File

@@ -208,19 +208,7 @@ describe('RocketLaunch preset', () => {
' </div>', ' </div>',
' </footer>', ' </footer>',
'', '',
' <script type="module">', ' <script type="module" src="/_merged_assets/scripts/init-navigation.js"></script>',
' import "@rocket/navigation/rocket-navigation.js";',
' import "@rocket/drawer/rocket-drawer.js";',
' const drawer = document.querySelector("#sidebar");',
'',
' // Toggle button',
` const triggers = document.querySelectorAll('[data-action="trigger-mobile-menu"]');`,
' for (const trigger of [...triggers]) {',
' trigger.addEventListener("click", function () {',
' drawer.opened = true;',
' });',
' }',
' </script>',
' </body>', ' </body>',
'</html>', '</html>',
].join('\n'), ].join('\n'),
@@ -443,19 +431,7 @@ describe('RocketLaunch preset', () => {
' </div>', ' </div>',
' </footer>', ' </footer>',
'', '',
' <script type="module">', ' <script type="module" src="/_merged_assets/scripts/init-navigation.js"></script>',
' import "@rocket/navigation/rocket-navigation.js";',
' import "@rocket/drawer/rocket-drawer.js";',
' const drawer = document.querySelector("#sidebar");',
'',
' // Toggle button',
` const triggers = document.querySelectorAll('[data-action="trigger-mobile-menu"]');`,
' for (const trigger of [...triggers]) {',
' trigger.addEventListener("click", function () {',
' drawer.opened = true;',
' });',
' }',
' </script>',
' </body>', ' </body>',
'</html>', '</html>',
].join('\n'), ].join('\n'),

View File

@@ -1,5 +1,11 @@
# Change Log # Change Log
## 0.7.1
### Patch Changes
- 2b7f1ee: Add support for pathprefix
## 0.7.0 ## 0.7.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@mdjs/core", "name": "@mdjs/core",
"version": "0.7.0", "version": "0.7.1",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
@@ -43,7 +43,7 @@
"remark" "remark"
], ],
"dependencies": { "dependencies": {
"@mdjs/mdjs-preview": "^0.4.0", "@mdjs/mdjs-preview": "^0.4.2",
"@mdjs/mdjs-story": "^0.2.0", "@mdjs/mdjs-story": "^0.2.0",
"@types/unist": "^2.0.3", "@types/unist": "^2.0.3",
"es-module-lexer": "^0.3.26", "es-module-lexer": "^0.3.26",

View File

@@ -1,8 +1,43 @@
const path = require('path');
const slash = require('slash');
/** @typedef {import('vfile').VFileOptions} VFileOptions */ /** @typedef {import('vfile').VFileOptions} VFileOptions */
/** @typedef {import('unist').Node} Node */ /** @typedef {import('unist').Node} Node */
/** @typedef {import('@mdjs/core/types/code').Story} Story */ /** @typedef {import('@mdjs/core/types/code').Story} Story */
function mdjsSetupCode({ rootNodeQueryCode = 'document', simulationSettings = {} } = {}) { /**
* @typedef {Object} simulationSettings
* @property {string} [simulatorUrl]
*/
/**
* @typedef {Object} rocketConfig
* @property {string} [pathPrefix]
*/
/**
* @param {object} options
* @param {string} [options.rootNodeQueryCode]
* @param {simulationSettings} [options.simulationSettings]
* @param {rocketConfig} [options.rocketConfig]
* @returns
*/
function mdjsSetupCode({
rootNodeQueryCode = 'document',
simulationSettings = {},
rocketConfig = {},
} = {}) {
if (rocketConfig && rocketConfig.pathPrefix) {
if (simulationSettings && simulationSettings.simulatorUrl) {
const { simulatorUrl } = simulationSettings;
if (simulatorUrl[0] === '/' && !simulatorUrl.startsWith(rocketConfig.pathPrefix)) {
simulationSettings.simulatorUrl = slash(
path.join(rocketConfig.pathPrefix, simulationSettings.simulatorUrl),
);
}
}
}
/** /**
* @param {Node} tree * @param {Node} tree
* @param {VFileOptions} file * @param {VFileOptions} file

View File

@@ -1,5 +1,19 @@
# @mdjs/mdjs-preview # @mdjs/mdjs-preview
## 0.4.2
### Patch Changes
- 72f631a: Improve customizations by hiding empty themes, platforms and adding parts to be styled.
- 74dd8d1: Autoheight will not grow bigger than the current size height
- 72f631a: Add a copy code button
## 0.4.1
### Patch Changes
- 0f6709a: Make sure initial settings are taken from the element if nothing is yet stored
## 0.4.0 ## 0.4.0
### Minor Changes ### Minor Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@mdjs/mdjs-preview", "name": "@mdjs/mdjs-preview",
"version": "0.4.0", "version": "0.4.2",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },

View File

@@ -51,6 +51,7 @@ export class MdJsPreview extends LitElement {
edgeDistance: { type: Boolean }, edgeDistance: { type: Boolean },
autoHeight: { type: Boolean }, autoHeight: { type: Boolean },
rememberSettings: { type: Boolean }, rememberSettings: { type: Boolean },
__copyButtonText: { type: String },
}; };
} }
@@ -61,18 +62,21 @@ export class MdJsPreview extends LitElement {
this.key = ''; this.key = '';
this.contentHeight = 0; this.contentHeight = 0;
this.simulatorUrl = ''; this.simulatorUrl = '';
this.__supportsClipboard = 'clipboard' in navigator;
this.__copyButtonText = 'Copy Code';
this.theme = 'light'; this.theme = 'light';
/** @type {{ key: string, name: string }[]} */
this.themes = [ this.themes = [
{ key: 'light', name: 'Light' }, // { key: 'light', name: 'Light' },
{ key: 'dark', name: 'Dark' }, // { key: 'dark', name: 'Dark' },
]; ];
this.language = 'en-US'; this.language = 'en-US';
this.languages = [ this.languages = [
{ key: 'en', name: 'English' }, { key: 'en', name: 'English' },
{ key: 'en-US', name: 'English (United States)' }, { key: 'en-US', name: 'English (United States)' },
{ key: 'en-US', name: 'English (United Kingdom)' }, { key: 'en-GB', name: 'English (United Kingdom)' },
{ key: 'de', name: 'German' }, { key: 'de', name: 'German' },
{ key: 'es', name: 'Spanish' }, { key: 'es', name: 'Spanish' },
{ key: 'fi', name: 'Finnish' }, { key: 'fi', name: 'Finnish' },
@@ -83,16 +87,17 @@ export class MdJsPreview extends LitElement {
{ key: 'pt', name: 'Portuguese' }, { key: 'pt', name: 'Portuguese' },
{ key: 'ro', name: 'Romanian' }, { key: 'ro', name: 'Romanian' },
{ key: 'sv', name: 'Swedish' }, { key: 'sv', name: 'Swedish' },
{ key: 'sv', name: 'Swedish' },
]; ];
this.platform = 'web'; this.platform = 'web';
/** @type {{ key: string, name: string }[]} */
this.platforms = [ this.platforms = [
{ key: 'web', name: 'Web' }, // { key: 'web', name: 'Web' },
// { key: 'web-windows', name: 'Windows' }, // { key: 'web-windows', name: 'Windows' },
// { key: 'web-mac', name: 'Mac' }, // { key: 'web-mac', name: 'Mac' },
{ key: 'android', name: 'Android' }, // { key: 'android', name: 'Android' },
{ key: 'ios', name: 'iOS' }, // { key: 'ios', name: 'iOS' },
]; ];
this.size = 'webSmall'; this.size = 'webSmall';
@@ -178,10 +183,11 @@ export class MdJsPreview extends LitElement {
} }
get deviceHeight() { get deviceHeight() {
const maxHeight = this.sizeData?.height || 50;
if (this.autoHeight) { if (this.autoHeight) {
return this.contentHeight + 10; return Math.min(this.contentHeight, maxHeight);
} }
return this.sizeData?.height || 50; return maxHeight;
} }
/** /**
@@ -269,10 +275,19 @@ export class MdJsPreview extends LitElement {
this.size = sizes[0].key; this.size = sizes[0].key;
} }
async onCopy() {
if (this.textContent) {
await navigator.clipboard.writeText(this.textContent.trim());
this.__copyButtonText = 'Copied ✅';
setTimeout(() => {
this.__copyButtonText = 'Copy code';
}, 2000);
}
}
renderPlatforms() { renderPlatforms() {
return html` if (this.platforms.length) {
<div> return html`
<h3>Platform</h3>
<h4>Platform</h4> <h4>Platform</h4>
<div <div
class="segmented-control" class="segmented-control"
@@ -298,14 +313,24 @@ export class MdJsPreview extends LitElement {
`, `,
)} )}
</div> </div>
</div> `;
`; }
}
renderPlatform() {
if (this.platforms.length) {
return html`
<div>
<h3>Platform</h3>
${this.renderPlatforms()}
</div>
`;
}
} }
renderSizes() { renderSizes() {
return html` if (this.sizes.length) {
<div> return html`
<h3>Viewport</h3>
<h4>Size</h4> <h4>Size</h4>
<div <div
class="segmented-control" class="segmented-control"
@@ -331,16 +356,22 @@ export class MdJsPreview extends LitElement {
`, `,
)} )}
</div> </div>
${this.renderAutoHeight()} `;
}
}
renderViewport() {
return html`
<div>
<h3>Viewport</h3>
${this.renderSizes()} ${this.renderAutoHeight()}
</div> </div>
`; `;
} }
renderThemes() { renderThemes() {
return html` if (this.themes.length) {
<div> return html`
<h3>Visual</h3>
<h4>Theme</h4>
<div <div
class="segmented-control" class="segmented-control"
@change=${ @change=${
@@ -365,15 +396,22 @@ export class MdJsPreview extends LitElement {
`, `,
)} )}
</div> </div>
${this.renderEdgeDistance()} `;
}
}
renderVisual() {
return html`
<div>
<h3>Visual</h3>
${this.renderThemes()} ${this.renderEdgeDistance()}
</div> </div>
`; `;
} }
renderLanguages() { renderLanguages() {
return html` if (this.languages.length) {
<div> return html`
<h3>Localization</h3>
<label> <label>
Language Language
<select <select
@@ -394,6 +432,15 @@ export class MdJsPreview extends LitElement {
)} )}
</select> </select>
</label> </label>
`;
}
}
renderLocalization() {
return html`
<div>
<h3>Localization</h3>
${this.renderLanguages()}
</div> </div>
`; `;
} }
@@ -403,7 +450,7 @@ export class MdJsPreview extends LitElement {
<div> <div>
<label class="${this.edgeDistance ? 'switch selected' : 'switch'}"> <label class="${this.edgeDistance ? 'switch selected' : 'switch'}">
Apply distance to edge Apply distance to edge
<span class="switch-button"></span> <span part="switch-button"></span>
<input <input
type="checkbox" type="checkbox"
@@ -426,7 +473,7 @@ export class MdJsPreview extends LitElement {
<div> <div>
<label class="${this.autoHeight ? 'switch selected' : 'switch'}"> <label class="${this.autoHeight ? 'switch selected' : 'switch'}">
Fit height to content Fit height to content
<span class="switch-button"></span> <span part="switch-button"></span>
<input <input
type="checkbox" type="checkbox"
?checked=${this.autoHeight} ?checked=${this.autoHeight}
@@ -448,7 +495,7 @@ export class MdJsPreview extends LitElement {
<div> <div>
<label class="${this.sameSettings ? 'switch selected' : 'switch'}"> <label class="${this.sameSettings ? 'switch selected' : 'switch'}">
Same settings for all simulations Same settings for all simulations
<span class="switch-button"></span> <span part="switch-button"></span>
<input <input
type="checkbox" type="checkbox"
?checked=${this.sameSettings} ?checked=${this.sameSettings}
@@ -473,7 +520,7 @@ export class MdJsPreview extends LitElement {
<div> <div>
<label class="${this.rememberSettings ? 'switch selected' : 'switch'}"> <label class="${this.rememberSettings ? 'switch selected' : 'switch'}">
Remember settings Remember settings
<span class="switch-button"></span> <span part="switch-button"></span>
<input <input
type="checkbox" type="checkbox"
?checked=${this.rememberSettings} ?checked=${this.rememberSettings}
@@ -506,11 +553,12 @@ export class MdJsPreview extends LitElement {
? html`<div>${this.story({ shadowRoot: this.shadowRoot })}</div>` ? html`<div>${this.story({ shadowRoot: this.shadowRoot })}</div>`
: html` : html`
<iframe <iframe
part="iframe"
csp=${`script-src ${document.location.origin} 'unsafe-inline'; connect-src ws://${document.location.host}/`} csp=${`script-src ${document.location.origin} 'unsafe-inline'; connect-src ws://${document.location.host}/`}
.src=${this.iframeUrl} .src=${this.iframeUrl}
style=${`width: ${this.sizeData.width}px; height: ${this.deviceHeight}px;`} style=${`width: ${this.sizeData.width}px; height: ${this.deviceHeight}px;`}
></iframe> ></iframe>
<p class="frame-description" style=${`width: ${this.sizeData.width + 4}px;`}> <p part="frame-description" style=${`width: ${this.sizeData.width + 4}px;`}>
${this.sizeData.name} - ${this.deviceHeight}x${this.sizeData.width} ${this.sizeData.name} - ${this.deviceHeight}x${this.sizeData.width}
</p> </p>
`} `}
@@ -523,8 +571,8 @@ export class MdJsPreview extends LitElement {
</h3> </h3>
<div slot="content"> <div slot="content">
<div class="settings-wrapper"> <div class="settings-wrapper">
${this.renderPlatforms()} ${this.renderSizes()} ${this.renderThemes()} ${this.renderPlatform()} ${this.renderViewport()} ${this.renderVisual()}
${this.renderLanguages()} ${this.renderSyncSettings()} ${this.renderLocalization()} ${this.renderSyncSettings()}
</div> </div>
</div> </div>
` `
@@ -533,7 +581,10 @@ export class MdJsPreview extends LitElement {
<button>Code</button> <button>Code</button>
</h3> </h3>
<div slot="content"> <div slot="content">
<slot></slot> <slot id="code-slot"></slot>
<button part="copy-button" @click="${this.onCopy}" ?hidden="${!this.__supportsClipboard}">
${this.__copyButtonText}
</button>
</div> </div>
</lion-accordion> </lion-accordion>
${this.simulatorUrl ${this.simulatorUrl
@@ -564,26 +615,45 @@ export class MdJsPreview extends LitElement {
background: #fff; background: #fff;
} }
[part='copy-button'] {
border: 1px solid var(--primary-color, #3f51b5);
border-radius: 9px;
padding: 7px;
background: none;
font-weight: bold;
color: var(--primary-color, #3f51b5);
text-align: center;
font-size: 12px;
line-height: 12px;
float: right;
margin-top: -10px;
}
[part='copy-button']:hover {
background-color: var(--primary-color, #3f51b5);
color: #fff;
}
.switch { .switch {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-bottom: 10px; margin-bottom: 10px;
} }
.switch:focus-within .switch-button { .switch:focus-within [part='switch-button'] {
box-shadow: 0 0 0 1px hsl(0deg 0% 100% / 40%), 0 0 0 4px rgb(31 117 203 / 48%); box-shadow: 0 0 0 1px hsl(0deg 0% 100% / 40%), 0 0 0 4px rgb(31 117 203 / 48%);
} }
.switch-button { [part='switch-button'] {
display: inline-block; display: inline-block;
width: 44px; width: 44px;
background: grey; background: #808080;
height: 25px; height: 25px;
border-radius: 15px; border-radius: 15px;
position: relative; position: relative;
} }
.switch-button::after { [part='switch-button']::after {
content: ' '; content: ' ';
width: 18px; width: 18px;
height: 18px; height: 18px;
@@ -595,16 +665,16 @@ export class MdJsPreview extends LitElement {
left: 4px; left: 4px;
} }
.switch.selected .switch-button { .switch.selected [part='switch-button'] {
background: green; background: var(--primary-color, #008000);
} }
.switch.selected .switch-button::after { .switch.selected [part='switch-button']::after {
left: auto; left: auto;
right: 4px; right: 4px;
} }
.frame-description { [part='frame-description'] {
margin: -5px 0 10px 0; margin: -5px 0 10px 0;
text-align: right; text-align: right;
font-size: 12px; font-size: 12px;
@@ -640,23 +710,23 @@ export class MdJsPreview extends LitElement {
} }
.controls a { .controls a {
color: #3f51b5; color: var(--primary-color, #3f51b5);
font-size: 14px; font-size: 14px;
line-height: 37px; line-height: 37px;
} }
.simulation-toggle { .simulation-toggle {
border: 1px solid #3f51b5; border: 1px solid var(--primary-color, #3f51b5);
border-radius: 9px; border-radius: 9px;
padding: 10px; padding: 10px;
background: none; background: none;
font-weight: bold; font-weight: bold;
color: #3f51b5; color: var(--primary-color, #3f51b5);
text-align: center; text-align: center;
} }
.simulation-toggle:hover { .simulation-toggle:hover {
background-color: #3f51b5; background-color: var(--primary-color, #3f51b5);
color: #fff; color: #fff;
} }
@@ -705,7 +775,7 @@ export class MdJsPreview extends LitElement {
} }
.segmented-control { .segmented-control {
border: 1px solid #3f51b5; border: 1px solid var(--primary-color, #3f51b5);
border-radius: 18px; border-radius: 18px;
display: inline-block; display: inline-block;
font-size: 14px; font-size: 14px;
@@ -728,7 +798,7 @@ export class MdJsPreview extends LitElement {
} }
.segmented-control label.selected span { .segmented-control label.selected span {
background: #3f51b5; background: var(--primary-color, #3f51b5);
color: #fff; color: #fff;
} }

View File

@@ -40,6 +40,8 @@ function storeSettings() {
} }
} }
let hasGlobalStateBeenSetBefore = false;
function restoreSettings() { function restoreSettings() {
for (const _sharedStateKey of Object.keys(_sharedStates)) { for (const _sharedStateKey of Object.keys(_sharedStates)) {
const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey); const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey);
@@ -55,6 +57,7 @@ function restoreSettings() {
default: default:
_sharedStates[sharedStateKey] = restoredValue; _sharedStates[sharedStateKey] = restoredValue;
} }
hasGlobalStateBeenSetBefore = true;
} }
} }
} }
@@ -66,27 +69,30 @@ restoreSettings();
* @param {import('./MdJsPreview.js').MdJsPreview} target * @param {import('./MdJsPreview.js').MdJsPreview} target
*/ */
export function applySharedStates(target) { export function applySharedStates(target) {
for (const _sharedStateKey of Object.keys(_sharedStates)) { if (hasGlobalStateBeenSetBefore) {
const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey); for (const _sharedStateKey of Object.keys(_sharedStates)) {
switch (sharedStateKey) { const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey);
case 'autoHeight': switch (sharedStateKey) {
case 'deviceMode': case 'autoHeight':
case 'rememberSettings': case 'deviceMode':
case 'edgeDistance': case 'rememberSettings':
target[sharedStateKey] = _sharedStates[sharedStateKey]; case 'edgeDistance':
break; target[sharedStateKey] = _sharedStates[sharedStateKey];
default: break;
target[sharedStateKey] = _sharedStates[sharedStateKey]; default:
target[sharedStateKey] = _sharedStates[sharedStateKey];
}
} }
} else {
_saveToSharedStates(target);
} }
} }
/** /**
* *
* @param {import('./MdJsPreview.js').MdJsPreview} target * @param {import('./MdJsPreview.js').MdJsPreview} target
* @param {Function} subscribedFn
*/ */
export function saveToSharedStates(target, subscribedFn) { function _saveToSharedStates(target) {
let updated = false; let updated = false;
for (const _sharedStateKey of Object.keys(_sharedStates)) { for (const _sharedStateKey of Object.keys(_sharedStates)) {
const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey); const sharedStateKey = /** @type {keyof _sharedStates} */ (_sharedStateKey);
@@ -102,8 +108,19 @@ export function saveToSharedStates(target, subscribedFn) {
_sharedStates[sharedStateKey] = target[sharedStateKey]; _sharedStates[sharedStateKey] = target[sharedStateKey];
} }
updated = true; updated = true;
hasGlobalStateBeenSetBefore = true;
} }
} }
return updated;
}
/**
*
* @param {import('./MdJsPreview.js').MdJsPreview} target
* @param {Function} subscribedFn
*/
export function saveToSharedStates(target, subscribedFn) {
const updated = _saveToSharedStates(target);
if (updated) { if (updated) {
storeSettings(); storeSettings();
for (const subscribeFn of subscribeFns) { for (const subscribeFn of subscribeFns) {

View File

@@ -1,5 +1,17 @@
# @rocket/search # @rocket/search
## 0.3.5
### Patch Changes
- 2b7f1ee: Add support for pathprefix
## 0.3.4
### Patch Changes
- 81edf45: Reduce the amount of js files in the build by avoiding inline script tags
## 0.3.3 ## 0.3.3
### Patch Changes ### Patch Changes

View File

@@ -1,6 +1,6 @@
{ {
"name": "@rocket/search", "name": "@rocket/search",
"version": "0.3.3", "version": "0.3.5",
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },

View File

@@ -0,0 +1 @@
import '@rocket/search/rocket-search.js';

View File

@@ -4,6 +4,4 @@
</svg> </svg>
</rocket-search> </rocket-search>
<script type="module"> <script type="module" src="{{ '/_assets/scripts/define-rocket-search.js' | asset | url }}"></script>
import '@rocket/search/rocket-search.js';
</script>

View File

@@ -9,7 +9,18 @@ export default {
absoluteBaseUrl: absoluteBaseUrlNetlify('http://localhost:8080'), absoluteBaseUrl: absoluteBaseUrlNetlify('http://localhost:8080'),
setupUnifiedPlugins: [ setupUnifiedPlugins: [
adjustPluginOptions('mdjsSetupCode', { adjustPluginOptions('mdjsSetupCode', {
simulationSettings: { simulatorUrl: '/simulator/' }, simulationSettings: {
simulatorUrl: '/simulator/',
themes: [
{ key: 'light', name: 'Light' },
{ key: 'dark', name: 'Dark' },
],
platforms: [
{ key: 'web', name: 'Web' },
{ key: 'android', name: 'Android' },
{ key: 'ios', name: 'iOS' },
],
},
}), }),
], ],