Skip to content
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

64 kiln alpha 47 updates #66

Merged
merged 3 commits into from
May 10, 2017
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
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"scripts": {
"lint": "eslint src",
"test": "npm run lint",
"test": "mocha; npm run lint",
"watch": "webpack -w",
"prepublish": "webpack -p"
},
Expand Down Expand Up @@ -37,10 +37,13 @@
"babel-core": "^6.14.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.14.0",
"chai": "^3.5.0",
"css-loader": "^0.24.0",
"eslint": "^3.3.1",
"extract-text-webpack-plugin": "^2.1.0",
"jsdom": "^10.1.0",
"lodash": "^4.14.2",
"mocha": "^3.3.0",
"node-sass": "^3.8.0",
"sass-loader": "^4.0.0",
"style-loader": "^0.13.1",
Expand Down
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import {
} from './mutationTypes';
// import invisibleLists from './services/invisible-lists';
import selectorService from './services/selector';
import { closest } from '@nymag/dom';
const PLUGIN_NAME = 'spaces-edit';

window.kiln = window.kiln || {};
window.kiln.plugins = window.kiln.plugins || {};

// TODO: remove this
window.kiln.on = window.kiln.on || function () {};
window.kiln.plugins[PLUGIN_NAME] = function spaceEdit(store) {
store.subscribe(function spaceEditHandleMutation(mutation, state) {
// wrap in a `try` so the UI doesn't stop working entirely
// if the DOM scraping below doesn't work
// if the code below breaks
try {
switch (mutation.type) {
case SELECT:
const el = mutation.payload,
ref = el.dataset.uri,
data = state.components[ref],
// find the <html> data-layout-uri attribute value
layoutRef = document.documentElement.dataset.layoutUri,
layoutData = state.components[layoutRef],
componentListName = closest(el, '[data-editable]').getAttribute('data-editable'),
componentList = layoutData[componentListName];
const {
el,
parentField,
parentURI,
uri
} = mutation.payload,
data = state.components[uri],
layoutData = state.components[parentURI],
componentListName = parentField.path,
componentList = layoutData[parentField.path],
componentListLayout = state.schemas.layout[componentListName];

if (componentList) {
selectorService.updateSelector(el, {data, ref}, state.schemas.layout[componentListName]);
selectorService.updateSelector(el, {data, uri}, componentListLayout);
}
// TODO: fix implementation of invisibleLists
// invisibleLists(el);
Expand Down
2 changes: 1 addition & 1 deletion src/services/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const kilnUtils = window.kiln.utils;
* the template (from template.hbs) to create a DOM element.
* If the template is not found, returns `null`.
* @return {Object | null}
* @param {String} templateSelector
* @param {String} selector
*/
function getFromTemplate(selector) {
const el = document.querySelector(selector);
Expand Down
33 changes: 28 additions & 5 deletions src/services/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,35 @@ var _ = require('lodash'),
SpaceSettings = require('../controllers/space-settings-controller'),
SpaceController = require('./../controllers/space-controller');

/* helper, will go away when API changes */
const addCreateSpaceButtonToPanel = clickHandler => panelEl => {
const createSpaceButton = references.getFromTemplate('.create-space');

panelEl.appendChild(createSpaceButton);
createSpaceButton.addEventListener('click', clickHandler);
};

/**
* TODO: swap this out with call to
* Kiln API for adding buttons when that API exists
*
* @param {Object} el
* @param {Object} options
* @param {Object} parent
*
*/
function addCreateSpaceButton(el, options, parent) {
const parentButton = dom.find(el, '.selected-actions'),
createSpaceButton = references.getFromTemplate('.create-space');
const clickHandler = createService.createSpace.bind(null, options, parent);

// we need to find the component settings panels (there are two) in the DOM,
// and we wait for a bit because the panel doesn't display
// right away
window.requestAnimationFrame(() => {
const settingsButtons = dom.findAll(document, '[title="Component Settings"]'),
panelEls = [].map.call(settingsButtons, el => el.parentElement);

parentButton.appendChild(createSpaceButton);
createSpaceButton.addEventListener('click', createService.createSpace.bind(null, options, parent));
panelEls.forEach(addCreateSpaceButtonToPanel(clickHandler));
});
}

/**
Expand Down Expand Up @@ -181,7 +204,7 @@ function updateSelector(el, options, parent) {
SpaceController(el, parent);
addToComponentList(el, options, parent);
} else if (!_.isEmpty(availableSpaces)) { // if element is space sibling
// addAvailableSpaces(el, availableSpaces);
addAvailableSpaces(el, availableSpaces);
addCreateSpaceButton(el, options, parent);
// TODO: figure this out, now that we're using Vuex
// we don't want it to be possible to add a space directly
Expand Down
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--reporter spec
--ui bdd
--recursive
src/**/*.test.js
3 changes: 3 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';
// don't truncate diffs
chai.config.truncateThreshold = 0;