Skip to content

Commit

Permalink
Merge branch 'main' into renovate/configure
Browse files Browse the repository at this point in the history
  • Loading branch information
auniverseaway committed Apr 19, 2024
2 parents 726abcb + 936c59f commit 818e59e
Show file tree
Hide file tree
Showing 45 changed files with 663 additions and 199 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ module.exports = {
overrides: [
{
files: ['test/**/*.js'],
rules: { 'no-console': 'off' },
rules: {
'no-console': 'off',
'import/no-unresolved': 'off',
},
},
],
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion blocks/browse/da-orgs/da-orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class DaOrgs extends LitElement {
</div>
</a>
</li>`)}
${this._orgs.length > 1 ? html`
${this._orgs.length > 4 ? html`
<li>
<a class="da-org new" href="/start">
<div class="new-icon">
Expand Down
2 changes: 2 additions & 0 deletions blocks/da-view/da-view-wc.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ h1 {
}

.da-content img {
object-fit: contain;
max-width: 100%;
height: 600px;
box-shadow: rgb(181 181 181) 0 0 20px 0;
}

Expand Down
2 changes: 1 addition & 1 deletion blocks/da-view/da-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DaView extends LitElement {
<h1>${this.details.name}</h1>
</div>
<div class="da-content">
<img src="${this.details.contentUrl}" />
<img src="${this.details.contentUrl}" width="900" height="600" />
</div>
`;
}
Expand Down
16 changes: 14 additions & 2 deletions blocks/edit/da-editor/da-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,22 @@ span.ProseMirror-menuseparator {
background: url('/blocks/edit/img/Smock_Unlink_18_N.svg') center / 18px no-repeat #EFEFEF;
}

.edit-list {
.bullet-list, .ProseMirror-menu-dropdown.list-menu {
background: url('/blocks/edit/img/Smock_TextBulleted_18_N.svg') center / 18px no-repeat #EFEFEF;
}

.ordered-list {
background: url('/blocks/edit/img/Smock_TextNumbered_18_N.svg') center / 18px no-repeat #EFEFEF;
}

.indent-list {
background: url('/blocks/edit/img/Smock_TextIndentIncrease_18_N.svg') center / 18px no-repeat #EFEFEF;
}

.outdent-list {
background: url('/blocks/edit/img/Smock_TextIndentDecrease_18_N.svg') center / 18px no-repeat #EFEFEF;
}

.insert-table {
background: url('/blocks/edit/img/Smock_TableAdd_18_N.svg') center / 18px no-repeat #EFEFEF;
}
Expand Down Expand Up @@ -263,7 +275,7 @@ span.ProseMirror-menuseparator {
background: url('/blocks/edit/img/Smock_Redo_18_N.svg') center / 18px no-repeat #EFEFEF;
}

/* Generic ProseMirror Styles */
/* Generic ProseMirror Styles */
.ProseMirror hr {
border-radius: 1px;
border: 1px solid #b3b3b3;
Expand Down
13 changes: 12 additions & 1 deletion blocks/edit/da-library/da-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class DaLibrary extends LitElement {
<li class="da-library-type-item">
<button class="da-library-type-item-btn"
@click=${() => this.handleItemClick(item)}>
<div class="da-library-type-item-detail">
<div class="da-library-type-item-detail">
${item.icon ? until(this.renderIcon(item.icon)) : ''}
<span>${name}</span>
<svg class="icon">
Expand Down Expand Up @@ -193,13 +193,24 @@ class DaLibrary extends LitElement {

customElements.define('da-library', DaLibrary);

const CLOSE_DROPDOWNS_EVENT = 'pm-close-dropdowns';

export default function open() {
const palettePane = window.view.dom.nextElementSibling;
const existingPalette = palettePane.querySelector('da-library');
if (existingPalette) {
existingPalette.remove();
return;
}
// close any other dropdowns
window.dispatchEvent(new CustomEvent(CLOSE_DROPDOWNS_EVENT));

const palette = document.createElement('da-library');
palettePane.append(palette);

const closePaletteListener = () => {
palette.remove();
window.removeEventListener(CLOSE_DROPDOWNS_EVENT, closePaletteListener);
};
window.addEventListener(CLOSE_DROPDOWNS_EVENT, closePaletteListener);
}
1 change: 1 addition & 0 deletions blocks/edit/da-title/da-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class DaTitle extends LitElement {
const { hash } = window.location;
const pathname = hash.replace('#', '');
// Only save to DA if it is a sheet or config

if (this.details.view === 'sheet') {
const dasSave = await saveToDa(pathname, this.sheet);
if (!dasSave.ok) return;
Expand Down
7 changes: 7 additions & 0 deletions blocks/edit/img/Smock_Cancel_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions blocks/edit/img/Smock_Checkmark_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions blocks/edit/img/Smock_Delete_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions blocks/edit/img/Smock_Edit_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions blocks/edit/img/Smock_TextIndentDecrease_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions blocks/edit/img/Smock_TextIndentIncrease_18_N.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions blocks/edit/prose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
goToNextCell,
tableNodes,
fixTables,
liftListItem,
sinkListItem,
gapCursor,
Y,
WebsocketProvider,
Expand Down Expand Up @@ -262,6 +264,8 @@ export default function initProse({ editor, path }) {
Tab: goToNextCell(1),
'Shift-Tab': goToNextCell(-1),
}),
keymap({ 'Shift-Tab': liftListItem(schema.nodes.list_item) }),
keymap({ Tab: sinkListItem(schema.nodes.list_item) }),
gapCursor(),
history(),
],
Expand Down
60 changes: 51 additions & 9 deletions blocks/edit/prose/plugins/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
undo,
redo,
wrapInList,
liftListItem,
sinkListItem,
// eslint-disable-next-line import/no-unresolved
} from 'da-y-wrapper';

Expand Down Expand Up @@ -55,10 +57,6 @@ function cmdItem(cmd, options) {
return new MenuItem(passedOptions);
}

function wrapListItem(nodeType, options) {
return cmdItem(wrapInList(nodeType, options.attrs), options);
}

function markActive(state, type) {
const { from, to, $from, $to, empty } = state.selection;
if (empty) {
Expand Down Expand Up @@ -284,6 +282,49 @@ function getTextBlocks(marks, nodes) {
];
}

function shouldEnableIndentOutdentIcon(state, listType) {
const { $from } = state.selection;
if ($from.node($from.depth - 1)?.type === listType) return true;
return false;
}

function getListMenu(nodes) {
return [
new MenuItem({
title: 'Bullet List',
label: 'Bullet List',
class: 'bullet-list',
run(initialState, dispatch) {
wrapInList(nodes.bullet_list)(initialState, dispatch);
},
}),
new MenuItem({
title: 'Ordered List',
label: 'Ordered List',
class: 'ordered-list',
run(state, dispatch) {
wrapInList(nodes.ordered_list)(state, dispatch);
},
}),
new MenuItem({
title: 'Indent List',
label: 'Indent List',
class: 'indent-list',
enable(state) { return shouldEnableIndentOutdentIcon(state, nodes.list_item); },
run(state, dispatch) {
sinkListItem(nodes.list_item)(state, dispatch);
},
}),
new MenuItem({
title: 'Outdent List',
label: 'Outdent List',
class: 'outdent-list',
enable(state) { return shouldEnableIndentOutdentIcon(state, nodes.list_item); },
run: liftListItem(nodes.list_item),
}),
];
}

function getMenu(view) {
const menu = document.createElement('div');
menu.className = 'ProseMirror-menubar';
Expand All @@ -302,10 +343,9 @@ function getMenu(view) {
];

const listMenu = [
wrapListItem(nodes.bullet_list, {
title: 'Wrap in bullet list',
label: 'List',
class: 'edit-list',
new Dropdown(getListMenu(nodes), {
label: 'List Menu',
class: 'list-menu',
}),
];

Expand All @@ -314,7 +354,9 @@ function getMenu(view) {
title: 'Open library',
label: 'Library',
enable() { return true; },
run() { openLibrary(); },
run() {
openLibrary();
},
class: 'open-library',
}),
new MenuItem({
Expand Down
30 changes: 26 additions & 4 deletions blocks/edit/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ async function saveHtml(fullPath) {
return daFetch(fullPath, opts);
}

async function saveJson(fullPath, sheet, dataType = 'blob') {
function formatSheetData(sheet) {
const jData = sheet.getData();

const data = jData.reduce((acc, row, idx) => {
if (idx > 0) {
const rowObj = {};
Expand All @@ -137,10 +138,31 @@ async function saveJson(fullPath, sheet, dataType = 'blob') {
emptyRow = false;
}
}
return data;
}

console.log(data);

const json = { total: data.length, offset: 0, limit: data.length, data, ':type': 'sheet' };
async function saveJson(fullPath, sheets, dataType = 'blob') {
let json;
const formatted = sheets.reduce((acc, sheet) => {
const data = formatSheetData(sheet);
acc[sheet.name] = {
total: data.length,
limit: data.length,
offset: 0,
data,
};
return acc;
}, {});

if (sheets.length > 1) {
formatted[':names'] = sheets.map((sheet) => sheet.name);
formatted[':version'] = 3;
formatted[':type'] = 'multi-sheet';
json = formatted;
} else {
json = formatted[sheets[0].name];
json[':type'] = 'sheet';
}

const formData = new FormData();

Expand Down
2 changes: 1 addition & 1 deletion blocks/shared/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const AEM_ORIGIN = 'https://admin.hlx.page';
const DA_ADMIN_ENVS = {
local: 'http://localhost:8787',
stage: 'https://stage-admin.da.live',
prod: 'https://da.live/api',
prod: 'https://admin.da.live',
};

const DA_COLLAB_ENVS = {
Expand Down
14 changes: 13 additions & 1 deletion blocks/shared/prose2aem.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ function removeMetadata(editor) {
editor.querySelector('.metadata')?.remove();
}

const iconRegex = /:([a-zA-Z0-9-]+?):/gm; // any alphanumeric character or - surrounded by :
function parseIcons(editor) {
if (!iconRegex.test(editor.innerHTML)) return;
editor.innerHTML = editor.innerHTML.replace(
iconRegex,
(_, iconName) => `<span class="icon icon-${iconName}"></span>`,
);
}

export default function prose2aem(editor, live) {
editor.removeAttribute('class');
editor.removeAttribute('contenteditable');
Expand All @@ -137,7 +146,10 @@ export default function prose2aem(editor, live) {

convertBlocks(editor);

if (live) removeMetadata(editor);
if (live) {
removeMetadata(editor);
parseIcons(editor);
}

makePictures(editor);

Expand Down

0 comments on commit 818e59e

Please sign in to comment.