Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tchak committed Jun 1, 2023
2 parents 029cc6f + 810f6ef commit f6c0032
Show file tree
Hide file tree
Showing 12 changed files with 640 additions and 633 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strict-peer-dependencies=false
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,37 @@
],
"scripts": {
"turbo": "turbo run test lint build",
"build": "turbo run --force build",
"build": "turbo run build --force",
"test": "turbo run test",
"lint": "turbo run lint",
"clean": "turbo run clean",
"prepare": "pnpm run build"
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
"@remix-run/node": "^1.15.0",
"@testing-library/dom": "^9.2.0",
"@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1",
"@vitest/browser": "^0.30.1",
"@vitest/ui": "^0.30.1",
"c8": "^7.13.0",
"@remix-run/node": "^1.16.1",
"@testing-library/dom": "^9.3.0",
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"@vitest/browser": "^0.31.4",
"@vitest/ui": "^0.31.4",
"c8": "^7.14.0",
"del-cli": "^5.0.0",
"eslint": "^8.39.0",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"jsdom": "^21.1.1",
"jsdom": "^22.1.0",
"msw": "^0.49.3",
"npm-run-all": "^4.1.5",
"playwright": "^1.32.3",
"playwright": "^1.34.3",
"prettier": "^2.8.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"turbo": "^1.9.3",
"rollup": "^3.23.0",
"turbo": "^1.10.1",
"typescript": "^5.0.4",
"vite": "^4.3.1",
"vitest": "^0.30.1",
"webdriverio": "^8.8.6"
"vite": "^4.3.9",
"vitest": "^0.31.4",
"webdriverio": "^8.10.6"
},
"engines": {
"node": ">=16"
Expand Down
6 changes: 6 additions & 0 deletions packages/actions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @coldwired/actions

## 0.11.0

### Minor Changes

- feat(actions): use data-turbo-force=“browser” instead of data-turbo-permanent

## 0.10.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": "./dist/index.cjs.js"
}
},
"version": "0.10.0",
"version": "0.11.0",
"keywords": [
"turbo"
],
Expand Down
16 changes: 8 additions & 8 deletions packages/actions/src/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('@coldwired/actions', () => {
actions.morph(from, '<div>World</div>');
expect(from.outerHTML).toEqual('<div class="bar">World</div>');

actions.morph(from, '<div data-turbo-force>World</div>');
actions.morph(from, '<div data-turbo-force="server">World</div>');
expect(from.outerHTML).toEqual('<div>World</div>');
});

Expand Down Expand Up @@ -464,7 +464,7 @@ describe('@coldwired/actions', () => {
actions.morph(
document,
parseHTMLDocument(
'<label for="test">Test</label><input data-turbo-force id="test" name="test" type="text" value="test" />'
'<label for="test">Test</label><input data-turbo-force="server" id="test" name="test" type="text" value="test" />'
)
);
expect(input.value).toEqual('test');
Expand Down Expand Up @@ -492,24 +492,24 @@ describe('@coldwired/actions', () => {

actions.morph(
document,
parseHTMLDocument('<div hidden aria-expanded data-turbo-force>New Menu</div>')
parseHTMLDocument('<div hidden aria-expanded data-turbo-force="server">New Menu</div>')
);
expect(from.getAttribute('aria-expanded')).toEqual('');
expect(from.hidden).toBeTruthy();
});

it('should preserve html if permanent attribute is set', async () => {
it('should preserve html if force="client" attribute is set', async () => {
actions.morph(document, parseHTMLDocument('<div>Hello world</div>'));
const from = document.body.firstElementChild as HTMLDivElement;
from.setAttribute('data-turbo-permanent', '');
from.setAttribute('data-turbo-force', 'browser');
actions.morph(document, parseHTMLDocument('<div>Bye world!</div>'));
expect(from.textContent).toEqual('Hello world');
actions.morph(document, parseHTMLDocument('<div>Encore !</div>'));
expect(from.textContent).toEqual('Hello world');
expect(from.hasAttribute('data-turbo-permanent')).toBeTruthy();
actions.morph(document, parseHTMLDocument('<div data-turbo-force>Bye world!</div>'));
expect(from.hasAttribute('data-turbo-force')).toBeTruthy();
actions.morph(document, parseHTMLDocument('<div data-turbo-force="server">Bye world!</div>'));
expect(from.textContent).toEqual('Bye world!');
expect(from.hasAttribute('data-turbo-permanent')).toBeFalsy();
expect(from.hasAttribute('data-turbo-force')).toBeFalsy();
});

it('should dispatch event', async () => {
Expand Down
17 changes: 10 additions & 7 deletions packages/actions/src/morph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { Metadata } from './metadata';
type MorphOptions = FocusNextOptions & {
childrenOnly?: boolean;
forceAttribute?: string;
permanentAttribute?: string;
metadata?: Metadata;
};

Expand Down Expand Up @@ -82,12 +81,11 @@ function morphToDocumentFragment(

function morphToElement(fromElement: Element, toElement: Element, options?: MorphOptions): void {
const forceAttribute = options?.forceAttribute;
const permanentAttribute = options?.permanentAttribute;

morphdom(fromElement, toElement, {
childrenOnly: options?.childrenOnly,
onBeforeElUpdated(fromElement: Element, toElement: Element) {
const force = forceAttribute ? !!toElement.closest(`[${forceAttribute}]`) : false;
const force = forceAttribute ? !!toElement.closest(`[${forceAttribute}="server"]`) : false;
const metadata = options?.metadata?.get(fromElement);

if (force && metadata) {
Expand All @@ -100,8 +98,8 @@ function morphToElement(fromElement: Element, toElement: Element, options?: Morp
return false;
}

if (!force && permanentAttribute) {
const permanent = !!fromElement.closest(`[${permanentAttribute}]`);
if (!force && forceAttribute) {
const permanent = !!fromElement.closest(`[${forceAttribute}="browser"]`);
if (permanent) {
return false;
}
Expand Down Expand Up @@ -142,9 +140,14 @@ function morphToElement(fromElement: Element, toElement: Element, options?: Morp
return true;
},
});

if (forceAttribute) {
fromElement.removeAttribute(forceAttribute);
for (const element of [...fromElement.querySelectorAll(`[${forceAttribute}]`)]) {
const forcedElements =
fromElement.getAttribute(forceAttribute) == 'server' ? [fromElement] : [];
for (const element of [
...forcedElements,
...fromElement.querySelectorAll(`[${forceAttribute}="server"]`),
]) {
element.removeAttribute(forceAttribute);
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/actions/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ export type Schema = {
forceAttribute: string;
focusGroupAttribute: string;
focusDirectionAttribute: string;
permanentAttribute: string;
hiddenClassName: string;
};

export const defaultSchema: Schema = {
forceAttribute: 'data-turbo-force',
focusGroupAttribute: 'data-turbo-focus-group',
focusDirectionAttribute: 'data-turbo-focus-direction',
permanentAttribute: 'data-turbo-permanent',
hiddenClassName: 'hidden',
};
8 changes: 8 additions & 0 deletions packages/router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @coldwired/router

## 0.11.0

### Patch Changes

- Updated dependencies
- @coldwired/actions@0.11.0
- @coldwired/turbo-stream@0.11.0

## 0.10.0

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": "./dist/index.cjs.js"
}
},
"version": "0.10.0",
"version": "0.11.0",
"keywords": [
"remix",
"router",
Expand All @@ -33,8 +33,8 @@
"clean": "del dist coverage node_modules/.vite"
},
"dependencies": {
"@coldwired/actions": "^0.10.0",
"@coldwired/turbo-stream": "^0.10.0",
"@coldwired/actions": "^0.11.0",
"@coldwired/turbo-stream": "^0.11.0",
"@coldwired/utils": "^0.10.0",
"@remix-run/router": "1.2.1",
"nanoid": "^4.0.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/turbo-stream/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @coldwired/turbo-stream

## 0.11.0

### Patch Changes

- Updated dependencies
- @coldwired/actions@0.11.0

## 0.10.0

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/turbo-stream/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": "./dist/index.cjs.js"
}
},
"version": "0.10.0",
"version": "0.11.0",
"keywords": [
"turbo"
],
Expand All @@ -31,7 +31,7 @@
"clean": "del dist coverage node_modules/.vite"
},
"dependencies": {
"@coldwired/actions": "^0.10.0",
"@coldwired/actions": "^0.11.0",
"@coldwired/utils": "^0.10.0",
"tiny-invariant": "^1.3.1"
},
Expand Down
Loading

0 comments on commit f6c0032

Please sign in to comment.