Skip to content

fix(playground): better handle multiple files for Javascript #3119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,10 @@ export default function Playground({
version,
};

let codeBlock;
if (!hasUsageTargetOptions) {
// codeSnippets are React components, so we need to get their rendered text
// using outerText will preserve line breaks for formatting in Stackblitz editor
codeBlock = codeRef.current.querySelector('code').outerText;
} else {
// using outerText will preserve line breaks for formatting in Stackblitz editor
const codeBlock = codeRef.current.querySelector('code').outerText;

if (hasUsageTargetOptions) {
editorOptions.files = Object.keys(codeSnippets[usageTarget])
.map((fileName) => ({
[fileName]: hostRef.current!.querySelector<HTMLElement>(`#${getCodeSnippetId(usageTarget, fileName)} code`)
Expand Down
2 changes: 1 addition & 1 deletion src/components/global/Playground/stackblitz.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const openHtmlEditor = async (code: string, options?: EditorOptions) => {

const package_json = defaultFiles[3];

files[indexHtml] = files[indexHtml].replace(/{{ TEMPLATE }}/g, code).replace(
files[indexHtml] = defaultFiles[1].replace(/{{ TEMPLATE }}/g, code).replace(
'</head>',
`
<script>
Expand Down
179 changes: 84 additions & 95 deletions static/usage/v6/modal/styling/animations/javascript/index_html.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,95 @@
```html
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core/css/core.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core/css/ionic.bundle.css" />
</head>
<ion-header>
<ion-toolbar>
<ion-title>App</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-button id="open-modal" expand="block">Open Modal</ion-button>

<body>
<ion-app>
<ion-header>
<ion-toolbar>
<ion-title>App</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-button id="open-modal" expand="block">Open Modal</ion-button>
<ion-modal trigger="open-modal">
<ion-header>
<ion-toolbar>
<ion-title>Modal</ion-title>
<ion-buttons slot="end">
<ion-button onclick="modal.dismiss()">Close</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=b" />
</ion-avatar>
<ion-label>
<h2>Connor Smith</h2>
<p>Sales Rep</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=a" />
</ion-avatar>
<ion-label>
<h2>Daniel Smith</h2>
<p>Product Designer</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=d" />
</ion-avatar>
<ion-label>
<h2>Greg Smith</h2>
<p>Director of Operations</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=e" />
</ion-avatar>
<ion-label>
<h2>Zoey Smith</h2>
<p>CEO</p>
</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-modal>
</ion-content>

<ion-modal trigger="open-modal">
<ion-header>
<ion-toolbar>
<ion-title>Modal</ion-title>
<ion-buttons slot="end">
<ion-button onclick="modal.dismiss()">Close</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=b" />
</ion-avatar>
<ion-label>
<h2>Connor Smith</h2>
<p>Sales Rep</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=a" />
</ion-avatar>
<ion-label>
<h2>Daniel Smith</h2>
<p>Product Designer</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=d" />
</ion-avatar>
<ion-label>
<h2>Greg Smith</h2>
<p>Director of Operations</p>
</ion-label>
</ion-item>
<ion-item>
<ion-avatar slot="start">
<ion-img src="https://i.pravatar.cc/300?u=e" />
</ion-avatar>
<ion-label>
<h2>Zoey Smith</h2>
<p>CEO</p>
</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-modal>
</ion-content>
</ion-app>
<script>
var modal = document.querySelector('ion-modal');

<script>
var modal = document.querySelector('ion-modal');
const enterAnimation = (baseEl) => {
const root = baseEl.shadowRoot;

const enterAnimation = (baseEl) => {
const root = baseEl.shadowRoot;
const backdropAnimation = createAnimation()
.addElement(root.querySelector('ion-backdrop'))
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');

const backdropAnimation = createAnimation()
.addElement(root.querySelector('ion-backdrop'))
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = createAnimation()
.addElement(root.querySelector('.modal-wrapper'))
.keyframes([
{ offset: 0, opacity: '0', transform: 'scale(0)' },
{ offset: 1, opacity: '0.99', transform: 'scale(1)' },
]);

const wrapperAnimation = createAnimation()
.addElement(root.querySelector('.modal-wrapper'))
.keyframes([
{ offset: 0, opacity: '0', transform: 'scale(0)' },
{ offset: 1, opacity: '0.99', transform: 'scale(1)' },
]);
return createAnimation()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
};

return createAnimation()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
};
const leaveAnimation = (baseEl) => enterAnimation(baseEl).direction('reverse');

const leaveAnimation = (baseEl) => enterAnimation(baseEl).direction('reverse');
modal.enterAnimation = enterAnimation;
modal.leaveAnimation = leaveAnimation;

modal.enterAnimation = enterAnimation;
modal.leaveAnimation = leaveAnimation;

function dismiss() {
modal.dismiss();
}
</script>
</body>
</html>
function dismiss() {
modal.dismiss();
}
</script>
```
89 changes: 38 additions & 51 deletions static/usage/v7/input/mask/javascript/index_html.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,45 @@
```html
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@7/css/core.css" />
<link rel="stylesheet" type="text/css" href="https://cdn.skypack.dev/@ionic/core@7/css/ionic.bundle.css" />
</head>
<ion-list>
<ion-item>
<ion-input id="card" label="Card number" placeholder="0000 0000 0000 0000"></ion-input>
</ion-item>
<ion-item>
<ion-input id="phone" label="US phone number" placeholder="+1 (xxx) xxx-xxxx"></ion-input>
</ion-item>
</ion-list>

<body>
<ion-app>
<ion-content class="ion-padding">
<ion-list>
<ion-item>
<ion-input id="card" label="Card number" placeholder="0000 0000 0000 0000"></ion-input>
</ion-item>
<ion-item>
<ion-input id="phone" label="US phone number" placeholder="+1 (xxx) xxx-xxxx"></ion-input>
</ion-item>
</ion-list>
</ion-content>
<script>
async function initPhoneMask() {
const ionInput = document.querySelector('#phone');
const nativeEl = await ionInput.getInputElement();

<script>
async function initPhoneMask() {
const ionInput = document.querySelector('#phone');
const nativeEl = await ionInput.getInputElement();
new window.Maskito(nativeEl, {
mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
});
}

new window.Maskito(nativeEl, {
mask: ['+', '1', ' ', '(', /\d/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/],
});
}
async function initCardMask() {
const ionInput = document.querySelector('#card');
const nativeEl = await ionInput.getInputElement();

async function initCardMask() {
const ionInput = document.querySelector('#card');
const nativeEl = await ionInput.getInputElement();
new window.Maskito(nativeEl, {
mask: [
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(3).fill(/\d/),
],
});
}

new window.Maskito(nativeEl, {
mask: [
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(4).fill(/\d/),
' ',
...Array(3).fill(/\d/),
],
});
}

window.addEventListener('appload', () => {
initCardMask();
initPhoneMask();
});
</script>
</ion-app>
</body>
</html>
window.addEventListener('appload', () => {
initCardMask();
initPhoneMask();
});
</script>
```
Loading